Restrict mobile types of function types.

Move ternary tests to semanticTests
This commit is contained in:
Daniel Kirchner
2023-07-18 14:13:36 +02:00
committed by Nikola Matic
parent 2c82873a2c
commit 110e2a656d
16 changed files with 153 additions and 37 deletions
@@ -0,0 +1,11 @@
error MyCustomError(uint, bool);
contract C {
function f() pure public {
true ? MyCustomError : MyCustomError;
}
}
// ----
// TypeError 9717: (93-106): Invalid mobile type in true expression.
// TypeError 3703: (109-122): Invalid mobile type in false expression.
@@ -1,18 +0,0 @@
error MyCustomError(uint, bool);
error MyCustomError2(uint, bool);
error MyCustomError3(uint, bool, bool);
contract C {
function f() pure public {
true ? MyCustomError : MyCustomError;
true ? MyCustomError : MyCustomError2;
true ? MyCustomError : MyCustomError3;
true ? MyCustomError : true;
true ? true : MyCustomError;
}
}
// ----
// TypeError 1080: (253-290): True expression's type error MyCustomError(uint256,bool) does not match false expression's type error MyCustomError3(uint256,bool,bool).
// TypeError 1080: (300-327): True expression's type error MyCustomError(uint256,bool) does not match false expression's type bool.
// TypeError 1080: (337-364): True expression's type bool does not match false expression's type error MyCustomError(uint256,bool).
@@ -0,0 +1,10 @@
contract C {
event MyCustomEvent(uint);
function f() pure public {
true ? MyCustomEvent : MyCustomEvent;
}
}
// ----
// TypeError 9717: (90-103): Invalid mobile type in true expression.
// TypeError 3703: (106-119): Invalid mobile type in false expression.
@@ -1,17 +0,0 @@
contract C {
event MyCustomEvent(uint);
event MyCustomEvent2(uint);
event MyCustomEvent3(uint, bool);
function f() pure public {
true ? MyCustomEvent : MyCustomEvent;
true ? MyCustomEvent : MyCustomEvent2;
true ? MyCustomEvent : MyCustomEvent3;
true ? MyCustomEvent : true;
true ? true : MyCustomEvent;
}
}
// ----
// TypeError 1080: (246-283): True expression's type event MyCustomEvent(uint256) does not match false expression's type event MyCustomEvent3(uint256,bool).
// TypeError 1080: (293-320): True expression's type event MyCustomEvent(uint256) does not match false expression's type bool.
// TypeError 1080: (330-357): True expression's type bool does not match false expression's type event MyCustomEvent(uint256).
@@ -0,0 +1,8 @@
contract C {
function f() public pure returns (uint x) {
x = (true ? addmod : addmod)(3, 4, 5);
}
}
// ----
// TypeError 9717: (81-87): Invalid mobile type in true expression.
// TypeError 3703: (90-96): Invalid mobile type in false expression.
@@ -0,0 +1,10 @@
contract C {
function f() external pure { }
function g() external pure { }
function test(bool b) public returns(bytes4) {
(b ? C.f : C.g).selector;
}
}
// ----
// TypeError 9717: (147-150): Invalid mobile type in true expression.
// TypeError 3703: (153-156): Invalid mobile type in false expression.
@@ -0,0 +1,13 @@
contract C {
function f() public pure { }
function g() public pure { }
}
contract A {
function test(bool b) public returns(bytes4) {
(b ? C.f : C.g).selector;
}
}
// ----
// TypeError 9717: (159-162): Invalid mobile type in true expression.
// TypeError 3703: (165-168): Invalid mobile type in false expression.
@@ -0,0 +1,16 @@
contract C {
function f() external pure { }
}
contract D {
function g() external pure { }
}
contract A {
function test(bool b) public returns(bytes4) {
(b ? C.f : D.g).selector;
}
}
// ----
// TypeError 9717: (179-182): Invalid mobile type in true expression.
// TypeError 3703: (185-188): Invalid mobile type in false expression.
@@ -0,0 +1,16 @@
interface I1 {
function f() external pure;
}
interface I2 {
function g() external pure;
}
contract C {
function test(bool b) public returns(bytes4) {
(b ? I1.f : I2.g).selector;
}
}
// ----
// TypeError 9717: (177-181): Invalid mobile type in true expression.
// TypeError 3703: (184-188): Invalid mobile type in false expression.