-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: disallow non-constant file-level variables
- Loading branch information
Showing
10 changed files
with
522 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// contract L { | ||
// function f(mapping(uint=>uint) storage x, mapping(uint=>uint) storage y) internal { | ||
// // x = y; | ||
// } | ||
// } |
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,46 @@ | ||
uint a = 0; //~ ERROR: only constant variables are allowed at file level | ||
uint constant b = 0; | ||
uint immutable c = 0; //~ ERROR: only constant variables are allowed at file level | ||
|
||
contract C { | ||
uint a2 = 0; | ||
uint constant b2 = 0; | ||
uint immutable c2 = 0; | ||
|
||
struct S { | ||
uint a3; | ||
uint constant b3; //~ ERROR: mutability is not allowed here | ||
uint immutable c3; //~ ERROR: mutability is not allowed here | ||
} | ||
|
||
error Er( | ||
uint a4, | ||
uint constant b4, //~ ERROR: mutability is not allowed here | ||
uint immutable c4 //~ ERROR: mutability is not allowed here | ||
); | ||
|
||
event Ev( | ||
uint a5, | ||
uint constant b5, //~ ERROR: mutability is not allowed here | ||
uint immutable c5 //~ ERROR: mutability is not allowed here | ||
); | ||
|
||
function f( | ||
uint a6, | ||
uint constant b6, //~ ERROR: mutability is not allowed here | ||
uint immutable c6 //~ ERROR: mutability is not allowed here | ||
) public returns( | ||
uint a7, | ||
uint constant b7, //~ ERROR: mutability is not allowed here | ||
uint immutable c7 //~ ERROR: mutability is not allowed here | ||
) { | ||
uint a8; | ||
uint constant b8; //~ ERROR: mutability is not allowed here | ||
uint immutable c8; //~ ERROR: mutability is not allowed here | ||
try this.f(0, 0, 0) returns( | ||
uint a9, | ||
uint constant b9, //~ ERROR: mutability is not allowed here | ||
uint immutable c9 //~ ERROR: mutability is not allowed here | ||
) {} catch {} | ||
} | ||
} |
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,114 @@ | ||
error: only constant variables are allowed at file level | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint a = 0; | ||
| ^^^^^^^^^^^ | ||
| | ||
|
||
error: only constant variables are allowed at file level | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint immutable c = 0; | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
|
||
error: mutability is not allowed here | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint constant b3; | ||
| ^^^^^^^^ | ||
| | ||
|
||
error: mutability is not allowed here | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint immutable c3; | ||
| ^^^^^^^^^ | ||
| | ||
|
||
error: mutability is not allowed here | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint constant b4, | ||
| ^^^^^^^^ | ||
| | ||
|
||
error: mutability is not allowed here | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint immutable c4 | ||
| ^^^^^^^^^ | ||
| | ||
|
||
error: mutability is not allowed here | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint constant b5, | ||
| ^^^^^^^^ | ||
| | ||
|
||
error: mutability is not allowed here | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint immutable c5 | ||
| ^^^^^^^^^ | ||
| | ||
|
||
error: mutability is not allowed here | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint constant b6, | ||
| ^^^^^^^^ | ||
| | ||
|
||
error: mutability is not allowed here | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint immutable c6 | ||
| ^^^^^^^^^ | ||
| | ||
|
||
error: mutability is not allowed here | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint constant b7, | ||
| ^^^^^^^^ | ||
| | ||
|
||
error: mutability is not allowed here | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint immutable c7 | ||
| ^^^^^^^^^ | ||
| | ||
|
||
error: mutability is not allowed here | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint constant b8; | ||
| ^^^^^^^^ | ||
| | ||
|
||
error: mutability is not allowed here | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint immutable c8; | ||
| ^^^^^^^^^ | ||
| | ||
|
||
error: mutability is not allowed here | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint constant b9, | ||
| ^^^^^^^^ | ||
| | ||
|
||
error: mutability is not allowed here | ||
--> ROOT/tests/ui/typeck/var_mutability.sol:LL:CC | ||
| | ||
LL | uint immutable c9 | ||
| ^^^^^^^^^ | ||
| | ||
|
||
error: aborting due to 16 previous errors | ||
|
Oops, something went wrong.