ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
22.68k stars 5.63k forks source link

The unary "+" in "((x) /= (2 % x)) + (-y)" reports an error #15236

Open haoyang9804 opened 3 days ago

haoyang9804 commented 3 days ago

Description

The unary "+" in "((x) /= (2 % x)) + (-y)" reports an error, but x = ((x) /= (2 % x)) + (-y) does not.

Environment

Steps to Reproduce

pragma solidity ^0.8.0;

contract Test {
  function f(int32 x) external pure returns (int32) {
    int32 y = 1;
    ((x) /= (2 % x)) + (-y);
    return 2;
  }
}

Compiling the above program raises an error complaining that + is disallowed in ((x) /= (2 % x)) + (-y);. However, when I change this expression statement into x = ((x) /= (2 % x)) + (-y);, the compiler does not raise the error. According to my understanding of Solidity type system, expr /= expr is an assignment expression, and its value equals the value of the left-hand-side identifier. I think + can connect the assignment expression and an identifier expression (-y).

ekpyron commented 2 days ago

Thanks for reporting, this is definitely an unintended regression introduced in 0.8.20!