-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Disallow the use of MagicType
in complex expressions
#14371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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. | ||
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kinda weird that these are separate errors, but not really an issue for now :) |
16 changes: 16 additions & 0 deletions
16
test/libsolidity/syntaxTests/metaTypes/runtimeCode_from_ternary_with_type_expression.sol
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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; | ||
matheusaaguiar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
// ---- | ||
// TypeError 9717: (93-104): Invalid mobile type in true expression. | ||
// TypeError 3703: (107-117): Invalid mobile type in false expression. |
This file contains hidden or 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 hidden or 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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.