0

Can anyone help me figure out the issue with this function in the code?

function getVerifiedProposals(uint index) public returns (string[] memory, string[][] memory, address, uint[] memory) {
        string[][] storage tempDocuments;
        address tempAddresses;
        uint[] memory tempAmount;
        
        if (allBidderProposals[index].status == ProposalStatus.verified) { 
            tempDocuments.push(allBidderProposals[index].constraintDocuments);
            tempAddresses = allBidderProposals[index].bidderAddress;
            tempAmount = allBidderProposals[index].quotationAmount;
        }
        return (constraints, tempDocuments, tempAddresses, tempAmount);
    } 

The error message shows :

Error: This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour.

1
  • Please, can you share all your smart contract code? Commented Apr 27, 2022 at 9:37

2 Answers 2

1

Here is the link to a GitHub issue that has the correct explanation. https://github.com/ethereum/solidity/issues/12549

Reasoning - If you are defining a local variable inside a function even if it's a storage type, it should point to a state variable. So, tempDocuments needs to point to a state variable.

I hope this resolves your issue.

The other answer on this post doesn't have the correct explanation so please ignore

0

I don't think you can declare an array inside a function and set the storage type as "storage". Every variable or array defined inside a function should always be of "memory" type.

string[][] memory tempDocuments;

This should resolve the issue.

Although I am not sure if this is a right approach. Solidity considers string as an array, so tempDocuments is actually a 3D array. Do check.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.