-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Propagate purity information for member access to foreign pure variables #12928
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
nishant-sachdeva
merged 1 commit into
ethereum:develop
from
StrongerXi:expand-purity-check-for-foreign-constants
Jun 16, 2022
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
29 changes: 29 additions & 0 deletions
29
test/libsolidity/syntaxTests/constants/constant_variables_as_static_array_length.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,29 @@ | ||
uint256 constant MAX = 1; | ||
|
||
library L1 { | ||
uint256 internal constant INT = 100; | ||
} | ||
|
||
contract C1 { | ||
uint256 internal constant CONST1 = L1.INT; | ||
|
||
uint256[L1.INT] internal arr1; // error, backward reference | ||
uint256[L2.INT] internal arr2; // error, forward reference | ||
} | ||
|
||
contract C2 is C1 { | ||
uint256 internal constant CONST2 = CONST1; | ||
|
||
uint256[CONST1] internal arr3; // error, inherited constants | ||
uint256[CONST2] internal arr4; // error, same contract constant | ||
} | ||
|
||
library L2 { | ||
uint256 internal constant INT = 100; | ||
} | ||
|
||
// ---- | ||
// TypeError 5462: (158-164): Invalid array length, expected integer literal or constant expression. | ||
// TypeError 5462: (222-228): Invalid array length, expected integer literal or constant expression. | ||
// TypeError 5462: (356-362): Invalid array length, expected integer literal or constant expression. | ||
// TypeError 5462: (421-427): Invalid array length, expected integer literal or constant expression. |
35 changes: 35 additions & 0 deletions
35
test/libsolidity/syntaxTests/constants/constant_with_dependencies_as_array_sizes.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,35 @@ | ||
uint256 constant MAX = 1; | ||
|
||
library L1 { | ||
uint256 internal constant INT = 100; | ||
} | ||
|
||
contract C1 { | ||
uint256 internal constant CONST = 20 + L2.INT; // forward reference | ||
uint256 internal constant LIMIT = MAX * L1.INT; // same file & external library constant | ||
uint256 internal constant NESTED = LIMIT + CONST; // nested & same contract constant | ||
|
||
uint256[L1.INT] internal arr1; // error, backward reference | ||
uint256[L2.INT] internal arr2; // error, forward reference | ||
} | ||
|
||
contract C2 is C1 { | ||
uint256 internal constant INHERITED = NESTED + CONST * LIMIT; // inherited constants | ||
} | ||
|
||
contract C3 is C2 { | ||
uint256 internal constant NESTED_INHERITED = INHERITED + NESTED + CONST * LIMIT; // nest-inherited constants | ||
|
||
uint256[CONST] internal arr3; // error, nest-inherited constants | ||
uint256[NESTED_INHERITED] internal arr4; // error, same contract constant | ||
} | ||
|
||
library L2 { | ||
uint256 internal constant INT = 100; | ||
} | ||
|
||
// ---- | ||
// TypeError 5462: (366-372): Invalid array length, expected integer literal or constant expression. | ||
// TypeError 5462: (430-436): Invalid array length, expected integer literal or constant expression. | ||
// TypeError 5462: (742-747): Invalid array length, expected integer literal or constant expression. | ||
// TypeError 5462: (822-838): Invalid array length, expected integer literal or constant expression. |
25 changes: 25 additions & 0 deletions
25
test/libsolidity/syntaxTests/constants/constant_with_dependencies_on_constants.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,25 @@ | ||
uint256 constant MAX = 1; | ||
|
||
library L1 { | ||
uint256 internal constant INT = 100; | ||
} | ||
|
||
contract C1 { | ||
uint256 internal constant CONST = 20 + L2.INT; // forward reference | ||
uint256 internal constant LIMIT = MAX * L1.INT; // same file & external library constant | ||
uint256 internal constant NESTED = LIMIT + CONST; // nested & same contract constant | ||
} | ||
|
||
contract C2 is C1 { | ||
uint256 internal constant INHERITED = NESTED + CONST * LIMIT; // inherited constants | ||
} | ||
|
||
contract C3 is C2 { | ||
uint256 internal constant NESTED_INHERITED = INHERITED + NESTED + CONST * LIMIT; // nest-inherited constants | ||
} | ||
|
||
library L2 { | ||
uint256 internal constant INT = 100; | ||
} | ||
|
||
// ---- |
11 changes: 11 additions & 0 deletions
11
.../libsolidity/syntaxTests/constants/constant_with_dependencies_on_file_level_constants.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,11 @@ | ||
==== Source: A.sol ==== | ||
import "B.sol" as B; | ||
|
||
uint constant X = 1; | ||
uint constant Y = B.Y; | ||
|
||
==== Source: B.sol ==== | ||
import "A.sol" as A; | ||
|
||
uint constant X = A.X; | ||
uint constant Y = 2; |
17 changes: 17 additions & 0 deletions
17
...ity/syntaxTests/constants/constants_with_dependencies_on_library_constants_multi_file.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,17 @@ | ||
==== Source: A.sol ==== | ||
import "B.sol"; | ||
|
||
library L { | ||
uint constant X = 1; | ||
uint constant Y = K.Y; | ||
} | ||
|
||
==== Source: B.sol ==== | ||
import "A.sol"; | ||
|
||
library K { | ||
uint constant X = L.X; | ||
uint constant Y = 2; | ||
} | ||
|
||
// ==== |
15 changes: 15 additions & 0 deletions
15
test/libsolidity/syntaxTests/constants/cyclic_dependency_file_and_library_constants.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.sol ==== | ||
import "B.sol"; | ||
|
||
uint256 constant A = B.VAL + 1; | ||
|
||
==== Source: B.sol ==== | ||
import "A.sol"; | ||
|
||
library B { | ||
uint256 constant VAL = A + 1; | ||
} | ||
|
||
// ---- | ||
// TypeError 6161: (B.sol:33-61): The value of the constant VAL has a cyclic dependency via A. | ||
// TypeError 6161: (A.sol:17-47): The value of the constant A has a cyclic dependency via VAL. |
13 changes: 13 additions & 0 deletions
13
test/libsolidity/syntaxTests/constants/cyclic_dependency_file_constants.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,13 @@ | ||
==== Source: A.sol ==== | ||
import "B.sol"; | ||
|
||
uint256 constant A = B + 1; | ||
|
||
==== Source: B.sol ==== | ||
import "A.sol"; | ||
|
||
uint256 constant B = A + 1; | ||
cameel marked this conversation as resolved.
Show resolved
Hide resolved
cameel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// ---- | ||
// TypeError 6161: (B.sol:17-43): The value of the constant B has a cyclic dependency via A. | ||
// TypeError 6161: (A.sol:17-43): The value of the constant A has a cyclic dependency via B. |
11 changes: 11 additions & 0 deletions
11
test/libsolidity/syntaxTests/constants/cyclic_dependency_library_constants.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,11 @@ | ||
library A { | ||
uint256 constant VAL = B.VAL + 1; | ||
} | ||
|
||
library B { | ||
uint256 constant VAL = A.VAL + 1; | ||
} | ||
|
||
// ---- | ||
// TypeError 6161: (16-48): The value of the constant VAL has a cyclic dependency via VAL. | ||
// TypeError 6161: (69-101): The value of the constant VAL has a cyclic dependency via VAL. |
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.