Disallow defining operators with non-pure functions

This commit is contained in:
Kamil Śliwak
2023-01-25 00:29:10 +01:00
parent 56ebb5f901
commit e0722732f6
7 changed files with 22 additions and 49 deletions
@@ -0,0 +1,24 @@
type Int is int16;
using {add as +} for Int;
function add(Int, Int) returns (Int) {
B b = new B();
return b.f();
}
contract B {
Int s;
function f() external returns (Int) {
s = Int.wrap(3);
return s;
}
}
contract C {
function test() public returns (Int) {
return Int.wrap(0) + Int.wrap(0);
}
}
// ----
// TypeError 7775: (27-30): Only pure functions can be used to define operators.
@@ -0,0 +1,12 @@
using {add as +, sub as -, mul as *} for A;
function add(A, A) view returns (A) {}
function sub(A, A) returns (A) {}
function mul(A, A) payable returns (A) {}
type A is address payable;
// ----
// TypeError 7775: (7-10): Only pure functions can be used to define operators.
// TypeError 7775: (17-20): Only pure functions can be used to define operators.
// TypeError 7775: (27-30): Only pure functions can be used to define operators.
// TypeError 9559: (118-159): Free functions cannot be payable.