Chahat
Chahat

Reputation: 39

Return argument type uint256[] storage ref is not implicitly convertible to expected type (type of first return variable) uint256

Return argument type uint256[] storage ref is not implicitly convertible to expected type (type of first return variable) uint256.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Types{
uint[] data;
uint8 j = 0;
function loop() public returns(uint){

    do{
        j++;
    data.push(j);
    }

 while(j < 5);

return data;  //error here
}

}

Upvotes: 0

Views: 4365

Answers (1)

Petr Hejda
Petr Hejda

Reputation: 43591

returns(uint)

This expression states that the function is supposed to return uint (an unsigned integer). But the actual code in the function returns uint[] (an array of unsigned integers).

Solution: Change the returns statement to

returns(uint[] memory)

Which means an array of unsigned integers, and the memory keywords is the data location of the reference type array.

Upvotes: 1

Related Questions