Skip to content

Commit 4edef4d

Browse files
committed
make state-variable-immutable override imply state-variable-assignment too
1 parent d2cf10b commit 4edef4d

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.3.25 (2023-07-05)
4+
5+
- Allow immutable variable assignment given `unsafe-allow state-variable-immutable`. Previously `unsafe-allow state-variable-assignment` was required as well.
6+
37
## 0.3.24 (2023-05-04)
48

59
- Allow constructor override at contract level.

contracts/TransformAllowedImmutable.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ pragma solidity ^0.8.2;
33

44
contract T1 {
55
uint immutable a = 1;
6-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
6+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
77
uint immutable b = 4;
88
uint immutable c = 3;
99
}
1010

1111
contract T2 {
1212
uint immutable a = 1;
13-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
13+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
1414
uint immutable b = 4;
1515
uint immutable c;
1616
/// @custom:oz-upgrades-unsafe-allow constructor

contracts/TransformCustomSize.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ struct OneAndAHalfSlot {
1313
}
1414

1515
contract SizeDefault {
16-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
16+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
1717
uint immutable w1 = block.number;
18-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
18+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
1919
uint immutable w2 = block.timestamp;
2020
uint immutable x; // slot 0 (after conversion to private)
2121
uint constant y = 1;
@@ -43,9 +43,9 @@ contract SizeDefault {
4343

4444
/// @custom:storage-size 128
4545
contract SizeOverride {
46-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
46+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
4747
uint immutable w1 = block.number;
48-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
48+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
4949
uint immutable w2 = block.timestamp;
5050
uint immutable x; // slot 0 (after conversion to private)
5151
uint constant y = 1;

src/transform-0.8.test.ts.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ Generated by [AVA](https://avajs.dev).
8787
c = 3;␊
8888
}␊
8989
uint a;␊
90-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
90+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable␊
9191
uint immutable b = 4;␊
9292
uint c;␊
9393
}␊
9494
9595
contract T2 {␊
9696
uint a = 1;␊
97-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
97+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable␊
9898
uint immutable b = 4;␊
9999
uint c;␊
100100
/// @custom:oz-upgrades-unsafe-allow constructor␊
@@ -131,9 +131,9 @@ Generated by [AVA](https://avajs.dev).
131131
}␊
132132
133133
contract SizeDefault {␊
134-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
134+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable␊
135135
uint immutable w1 = block.number;␊
136-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
136+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable␊
137137
uint immutable w2 = block.timestamp;␊
138138
uint x; // slot 0 (after conversion to private)␊
139139
uint constant y = 1;␊
@@ -177,9 +177,9 @@ Generated by [AVA](https://avajs.dev).
177177
178178
/// @custom:storage-size 128␊
179179
contract SizeOverride {␊
180-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
180+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable␊
181181
uint immutable w1 = block.number;␊
182-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
182+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable␊
183183
uint immutable w2 = block.timestamp;␊
184184
uint x; // slot 0 (after conversion to private)␊
185185
uint constant y = 1;␊

src/transform-0.8.test.ts.snap

-13 Bytes
Binary file not shown.

src/utils/upgrades-overrides.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ export function hasOverride(
2323
override: ValidationErrorKind,
2424
resolver: ASTResolver,
2525
): boolean {
26-
return getOverrides(node, resolver).includes(override);
26+
const overrides = getOverrides(node, resolver);
27+
return (
28+
overrides.includes(override) ||
29+
(override === 'state-variable-assignment' &&
30+
node.nodeType === 'VariableDeclaration' &&
31+
node.mutability === 'immutable' &&
32+
overrides.includes('state-variable-immutable'))
33+
);
2734
}
2835

2936
export function getOverrides(node: Node, resolver: ASTResolver): ValidationErrorKind[] {

0 commit comments

Comments
 (0)