mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
User-defined operators on structs
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
struct S { Z z; }
|
||||
struct Z { int x; }
|
||||
|
||||
using {addS as +} for S;
|
||||
using {addZ as +} for Z;
|
||||
|
||||
function addS(S memory, S memory) pure returns (S memory) {}
|
||||
function addZ(Z memory, Z memory) pure returns (Z memory) { revert(); }
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
S(Z(1)) + S(Z(2) + Z(3));
|
||||
S(Z(4)) + S(Z(5)); // Unreachable
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 5740: (310-327): Unreachable code.
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
struct S { Z z; }
|
||||
struct Z { int x; }
|
||||
|
||||
using {unsubS as -} for S;
|
||||
using {unsubZ as -} for Z;
|
||||
|
||||
function unsubS(S memory) pure returns (S memory) {}
|
||||
function unsubZ(Z memory) pure returns (Z memory) { revert(); }
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
-S(-Z(1));
|
||||
-S(Z(2)); // Unreachable
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 5740: (283-291): Unreachable code.
|
||||
Reference in New Issue
Block a user