solang icon indicating copy to clipboard operation
solang copied to clipboard

[Inconsistent with solc]: Variable overriding a function causes unexpected execution results.

Open Subway2023 opened this issue 8 months ago • 2 comments

Solang version: v0.3.3-70-g32a45ea1 Description: Calling the foo function of contract X fails when using solc + EVM, but succeeds when using solang + SVM, returning 5 (which is an incorrect value).

contract A {
    function foo() external virtual view returns(uint) { return 4; }
    function foo(uint) external virtual view returns(uint) { return 4; }
    function foo(uint, uint) external view virtual returns(uint) { return 4; }
}

contract X is A {
    uint public override foo = 5;
}

Subway2023 avatar Mar 23 '25 08:03 Subway2023

Yes, we can simply change the variable name foo to avoid conflict with the inherited function. If the intention is to return the value 5, the correct approach is to override the foo() function in the derived contract and return 5 from the function instead of declaring a conflicting public variable.

HMSagar2701 avatar Mar 24 '25 04:03 HMSagar2701

Thank you very much, this is a great solution to correct result. Similar to other issues, another purpose of mine is to test the differences between solc+evm and solang+svm.

Subway2023 avatar Mar 24 '25 04:03 Subway2023