-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14371 from ethereum/overrideMagicType_mobileType
Disallow the use of `MagicType` in complex expressions
- Loading branch information
Showing
16 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
test/libsolidity/semanticTests/expressions/module_from_ternary_expression.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
==== Source: A ==== | ||
contract C { | ||
} | ||
==== Source: B ==== | ||
import "A" as M; | ||
|
||
contract C { | ||
function f() public pure returns (bool) { | ||
bool flag; | ||
((flag = true) ? M : M).C; | ||
return flag; | ||
} | ||
} | ||
// ---- | ||
// f() -> true |
9 changes: 9 additions & 0 deletions
9
test/libsolidity/semanticTests/expressions/tuple_from_ternary_expression.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
contract C { | ||
function f() public pure returns (bool){ | ||
bool flag; | ||
((flag = true) ? (1, 2, 3) : (3, 2, 1)); | ||
return flag; | ||
} | ||
} | ||
// ---- | ||
// f() -> true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
test/libsolidity/syntaxTests/imports/module_function_from_ternary_expression.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
==== Source: A ==== | ||
function f() pure returns (uint) { | ||
return 42; | ||
} | ||
==== Source: B ==== | ||
function f() pure returns (uint) { | ||
return 24; | ||
} | ||
==== Source: C ==== | ||
import "A" as A; | ||
import "B" as B; | ||
|
||
contract C { | ||
function f(bool b) public pure returns (uint) { | ||
return (b ? A : B).f(); | ||
} | ||
} | ||
// ---- | ||
// TypeError 1080: (C:116-125): True expression's type module "A" does not match false expression's type module "B". |
7 changes: 7 additions & 0 deletions
7
test/libsolidity/syntaxTests/inline_arrays/unnamed_type_tuple_in_inline_array.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
contract C { | ||
function f() public { | ||
[(1, 2, 3), (4, 5, 6)]; | ||
} | ||
} | ||
// ---- | ||
// TypeError 9656: (47-69): Unable to deduce nameable type for array elements. Try adding explicit type conversion for the first element. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test/libsolidity/syntaxTests/metaTypes/max_keyword_from_ternary_with_type_expression.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
contract C { | ||
function max(bool isUint) pure public returns (uint8) { | ||
return (isUint ? type(uint8) : type(int8)).max; | ||
} | ||
} | ||
// ---- | ||
// TypeError 9717: (98-109): Invalid mobile type in true expression. | ||
// TypeError 3703: (112-122): Invalid mobile type in false expression. |
16 changes: 16 additions & 0 deletions
16
test/libsolidity/syntaxTests/metaTypes/runtimeCode_from_ternary_with_type_expression.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
contract A { | ||
function f() public {} | ||
} | ||
|
||
contract B { | ||
function g() public {} | ||
} | ||
|
||
contract C { | ||
function ab(bool getA) pure public returns (bytes memory) { | ||
return (getA ? type(A) : type(B)).runtimeCode; | ||
} | ||
} | ||
// ---- | ||
// TypeError 9717: (186-193): Invalid mobile type in true expression. | ||
// TypeError 3703: (196-203): Invalid mobile type in false expression. |
6 changes: 6 additions & 0 deletions
6
test/libsolidity/syntaxTests/metaTypes/type_expression_tuple_max.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
contract C { | ||
function max() public pure returns (uint8) { | ||
return (type(uint8)).max; | ||
} | ||
} | ||
// ---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
contract C { | ||
function max() public pure returns (uint8) { | ||
return type(uint8).max; | ||
} | ||
} | ||
// ---- |
8 changes: 8 additions & 0 deletions
8
test/libsolidity/syntaxTests/metaTypes/type_max_from_ternary_expression.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
contract C { | ||
function max(bool isUint) public returns (uint8) { | ||
return (isUint ? type(uint8) : type(int8)).max; | ||
} | ||
} | ||
// ---- | ||
// TypeError 9717: (93-104): Invalid mobile type in true expression. | ||
// TypeError 3703: (107-117): Invalid mobile type in false expression. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
contract A { | ||
} | ||
|
||
contract C { | ||
function f() public pure returns (bytes memory) { | ||
return type(A).runtimeCode; | ||
} | ||
} | ||
// ---- |
14 changes: 14 additions & 0 deletions
14
test/libsolidity/syntaxTests/metaTypes/type_runtimecode_from_ternary_expression_.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
contract A { | ||
} | ||
|
||
contract B { | ||
} | ||
|
||
contract C { | ||
function f(bool getA) public returns (bytes memory) { | ||
return (getA ? type(A) : type(B)).runtimeCode; | ||
} | ||
} | ||
// ---- | ||
// TypeError 9717: (126-133): Invalid mobile type in true expression. | ||
// TypeError 3703: (136-143): Invalid mobile type in false expression. |