Skip to content

Commit

Permalink
Dont allow initialization of transient storage state variables
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusaaguiar committed Aug 9, 2024
1 parent 55a5fd9 commit da68f49
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
8 changes: 8 additions & 0 deletions libsolidity/analysis/DeclarationTypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,14 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
_variable.location(),
"Transient cannot be used as data location for constant or immutable variables."
);

if (_variable.value())
m_errorReporter.declarationError(
9825_error,
_variable.location(),
"Initialization of transient storage state variables is not supported."
);

typeLoc = DataLocation::Transient;
break;
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
contract C {
uint transient x = 42;
function test() public view { assert(x == 42); }
uint transient x;
function test() public view { assert(x == 0); }
}
// ====
// SMTEngine: all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ contract C {
}
// ----
// DeclarationError 2197: (17-52): Transient cannot be used as data location for constant or immutable variables.
// DeclarationError 9825: (17-52): Initialization of transient storage state variables is not supported.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
contract D { }

contract C {
int transient x = -99;
address transient a = address(0xABC);
bool transient b = x > 0 ? false : true;
}
// ----
// DeclarationError 9825: (30-51): Initialization of transient storage state variables is not supported.
// DeclarationError 9825: (54-90): Initialization of transient storage state variables is not supported.
// DeclarationError 9825: (93-132): Initialization of transient storage state variables is not supported.

0 comments on commit da68f49

Please sign in to comment.