Skip to content

Commit 3259d78

Browse files
Add and update tests
1 parent d6a396e commit 3259d78

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
contract A {
2+
uint constant INHERITED = 42;
3+
}
4+
5+
contract C is A {
6+
uint constant CONST = 64;
7+
uint[A.INHERITED] x;
8+
uint[C.CONST] y;
9+
}
10+
// ----
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
contract A {
2+
uint constant INHERITED = 1;
3+
}
4+
contract C is A {
5+
uint constant CONST = 2 + A.INHERITED;
6+
uint[CONST] array;
7+
}
8+
// ----

test/libsolidity/syntaxTests/constants/constant_variables_as_static_array_length.sol

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,20 @@ library L1 {
77
contract C1 {
88
uint256 internal constant CONST1 = L1.INT;
99

10-
uint256[L1.INT] internal arr1; // error, backward reference
10+
uint256[L1.INT] internal arr1;
1111
uint256[L2.INT] internal arr2; // error, forward reference
1212
}
1313

1414
contract C2 is C1 {
1515
uint256 internal constant CONST2 = CONST1;
1616

17-
uint256[CONST1] internal arr3; // error, inherited constants
18-
uint256[CONST2] internal arr4; // error, same contract constant
17+
uint256[CONST1] internal arr3;
18+
uint256[CONST2] internal arr4;
1919
}
2020

2121
library L2 {
2222
uint256 internal constant INT = 100;
2323
}
2424

2525
// ----
26-
// TypeError 5462: (158-164): Invalid array length, expected integer literal or constant expression.
27-
// TypeError 5462: (222-228): Invalid array length, expected integer literal or constant expression.
28-
// TypeError 5462: (356-362): Invalid array length, expected integer literal or constant expression.
29-
// TypeError 5462: (421-427): Invalid array length, expected integer literal or constant expression.
26+
// TypeError 5462: (193-199): Invalid array length, expected integer literal or constant expression.

test/libsolidity/syntaxTests/constants/constant_with_dependencies_as_array_sizes.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ library L1 {
55
}
66

77
contract C1 {
8-
uint256 internal constant CONST = 20 + L2.INT; // forward reference
8+
uint256 internal constant CONST = 30 + L1.INT; // backward reference
9+
uint256 internal constant CONST2 = 30 + L2.INT; // forward reference
910
uint256 internal constant LIMIT = MAX * L1.INT; // same file & external library constant
1011
uint256 internal constant NESTED = LIMIT + CONST; // nested & same contract constant
1112

12-
uint256[L1.INT] internal arr1; // error, backward reference
13+
uint256[L1.INT] internal arr1; // ok, backward reference
1314
uint256[L2.INT] internal arr2; // error, forward reference
15+
uint256[CONST2] internal arr3; // error, computed with forward reference
1416
}
1517

1618
contract C2 is C1 {
@@ -20,16 +22,14 @@ contract C2 is C1 {
2022
contract C3 is C2 {
2123
uint256 internal constant NESTED_INHERITED = INHERITED + NESTED + CONST * LIMIT; // nest-inherited constants
2224

23-
uint256[CONST] internal arr3; // error, nest-inherited constants
24-
uint256[NESTED_INHERITED] internal arr4; // error, same contract constant
25+
uint256[CONST] internal arr4; // nest-inherited constants
26+
uint256[NESTED_INHERITED] internal arr5; // same contract constant
2527
}
2628

2729
library L2 {
2830
uint256 internal constant INT = 100;
2931
}
3032

3133
// ----
32-
// TypeError 5462: (366-372): Invalid array length, expected integer literal or constant expression.
33-
// TypeError 5462: (430-436): Invalid array length, expected integer literal or constant expression.
34-
// TypeError 5462: (742-747): Invalid array length, expected integer literal or constant expression.
35-
// TypeError 5462: (822-838): Invalid array length, expected integer literal or constant expression.
34+
// TypeError 5462: (501-507): Invalid array length, expected integer literal or constant expression.
35+
// TypeError 5462: (564-570): Invalid array length, expected integer literal or constant expression.

0 commit comments

Comments
 (0)