solang icon indicating copy to clipboard operation
solang copied to clipboard

[Inconsistent with solc]: The assignment order is different.

Open Subway2023 opened this issue 8 months ago • 3 comments

Solang version: v0.3.3-70-g32a45ea1 Description: In solc + EVM, the value of y is 1, but in solang + SVM, the value of y is 3.

contract C {
    uint256 x;
    uint256 y;
    function set(uint256 v) public returns (uint256) { x = v; return v; }
    function f() public returns (uint256) {
       (y, y, y) = (set(1), set(2), set(3));
       return y;
    }
}

Subway2023 avatar Mar 23 '25 09:03 Subway2023

Hi @Subway2023 , can you please check the below code, above you are assigning multiple values for same variable, below approach may fix the issue and returns value y=3.

```
contract C {
    uint256 x;
    uint256 y;

    function set(uint256 v) public returns (uint256) {
        x = v;
        return v;
    }

    function f() public returns (uint256) {
        uint256 a = set(1);
        uint256 b = set(2);
        uint256 c = set(3);
        y = c; 
        return y;
    }
}
``` pre>

HMSagar2701 avatar Mar 24 '25 04:03 HMSagar2701

Yes, the code you provided produces the correct answer. My goal is to expose the inconsistencies between solc and solang.

Subway2023 avatar Mar 24 '25 04:03 Subway2023

ok, got it

HMSagar2701 avatar Mar 24 '25 04:03 HMSagar2701