mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix reads checks for immutable variables.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
contract A {
|
||||
int immutable a;
|
||||
constructor() { a = 5; }
|
||||
function f() public { a += 7; }
|
||||
}
|
||||
|
||||
// ----
|
||||
// TypeError 1581: (83-84): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
@@ -6,4 +6,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 4599: (86-87): Immutable variables must be initialized unconditionally, not in an if statement.
|
||||
// TypeError 4599: (86-87): Cannot write to immutable here: Immutable variables cannot be initialized inside an if statement.
|
||||
|
||||
@@ -9,4 +9,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 1581: (119-120): Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
// TypeError 1581: (119-120): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
|
||||
@@ -9,4 +9,4 @@ contract C {
|
||||
function f(uint a) internal pure {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 1581: (59-60): Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
// TypeError 1581: (59-60): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
|
||||
@@ -8,4 +8,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 1581: (102-103): Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
// TypeError 1581: (102-103): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
contract C {
|
||||
uint immutable x = 3;
|
||||
uint immutable x;
|
||||
constructor() {
|
||||
x--;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 7733: (67-68): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
|
||||
// TypeError 7733: (63-64): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
contract C {
|
||||
uint immutable x = 3;
|
||||
uint immutable x;
|
||||
constructor() {
|
||||
delete x;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 7733: (74-75): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
|
||||
// TypeError 7733: (70-71): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
uint immutable x = 3;
|
||||
constructor() {
|
||||
delete x;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 1574: (74-75): Immutable state variable already initialized.
|
||||
// TypeError 7733: (74-75): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
|
||||
@@ -10,5 +10,4 @@ contract C is B(C.f) {
|
||||
function f() internal returns(uint) { return x = 2; }
|
||||
}
|
||||
// ----
|
||||
// TypeError 1581: (200-201): Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
// TypeError 1574: (200-201): Immutable state variable already initialized.
|
||||
// TypeError 1581: (200-201): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
contract C {
|
||||
uint immutable x = 3;
|
||||
uint immutable x;
|
||||
constructor() {
|
||||
x++;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 7733: (67-68): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
|
||||
// TypeError 7733: (63-64): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
uint immutable x;
|
||||
uint immutable y;
|
||||
constructor() {
|
||||
++x;
|
||||
--y;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 7733: (77-78): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
|
||||
// TypeError 7733: (86-87): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
|
||||
@@ -11,4 +11,4 @@ contract C is B {
|
||||
constructor() B(y = 3) { }
|
||||
}
|
||||
// ----
|
||||
// TypeError 1581: (148-149): Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
// TypeError 1581: (148-149): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
|
||||
+1
-1
@@ -10,4 +10,4 @@ contract C is B(C.y = 3) {
|
||||
uint immutable y;
|
||||
}
|
||||
// ----
|
||||
// TypeError 1581: (104-107): Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
// TypeError 1581: (104-107): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
|
||||
@@ -8,5 +8,4 @@ contract C is B {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 7484: (88-89): Immutable variables must be initialized in the constructor of the contract they are defined in.
|
||||
// TypeError 1574: (88-89): Immutable state variable already initialized.
|
||||
// TypeError 7484: (88-89): Cannot write to immutable here: Immutable variables must be initialized in the constructor of the contract they are defined in.
|
||||
|
||||
@@ -6,4 +6,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 6672: (88-89): Immutable variables can only be initialized once, not in a while statement.
|
||||
// TypeError 6672: (88-89): Cannot write to immutable here: Immutable variables cannot be initialized inside a loop.
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
contract A {
|
||||
int immutable a;
|
||||
constructor() { a = 5; }
|
||||
function f() public { --a; }
|
||||
}
|
||||
|
||||
// ----
|
||||
// TypeError 1581: (85-86): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
@@ -6,5 +6,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 1581: (76-77): Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
// TypeError 1574: (76-77): Immutable state variable already initialized.
|
||||
// TypeError 1581: (76-77): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
|
||||
@@ -8,5 +8,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 1581: (111-112): Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
// TypeError 1574: (111-112): Immutable state variable already initialized.
|
||||
// TypeError 1581: (111-112): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
|
||||
|
||||
Reference in New Issue
Block a user