Encode-Club-Solidity-Foundations / Lesson-03

4 stars 7 forks source link

Invalid implicit conversion error #4

Open Flyingtothemoon123 opened 2 years ago

Flyingtothemoon123 commented 2 years ago

I have a function that takes uint256 with array type as an argument. After running the code the following error pops - up:

TypeError: Invalid type for argument in function call. Invalid implicit conversion from uint256[3] memory to uint256[] memory requested.

My code:

contract Testingground { uint256[] private threshold = [1000, 2000, 3000];

function setThreshold(uint256[] memory _threshold) public onlyOwner {       
    threshold = _threshold;
}

}

MatheusDaros commented 2 years ago

Hello @Flyingtothemoon123 To do that you'll need a for loop, unfortunately. You can only copy fixed size arrays inside other fixed size arrays of same size. There is no implicitly defined conversions between fixed size arrays and dynamic arrays in solidity.