Properly handle assignments of immutables at declaration.

This commit is contained in:
Daniel Kirchner
2020-04-02 08:35:22 +02:00
parent 82f57f0465
commit 77ea896b68
4 changed files with 14 additions and 2 deletions
+1 -1
View File
@@ -550,7 +550,7 @@ void ContractCompiler::initializeStateVariables(ContractDefinition const& _contr
{
solAssert(!_contract.isLibrary(), "Tried to initialize state variables of library.");
for (VariableDeclaration const* variable: _contract.stateVariables())
if (variable->value() && !variable->isConstant() && !variable->immutable())
if (variable->value() && !variable->isConstant())
ExpressionCompiler(m_context, m_optimiserSettings.runOrderLiterals).appendStateVariableInitialization(*variable);
}
+4 -1
View File
@@ -73,7 +73,10 @@ void ExpressionCompiler::appendStateVariableInitialization(VariableDeclaration c
utils().convertType(*type, *_varDecl.annotation().type);
type = _varDecl.annotation().type;
}
StorageItem(m_context, _varDecl).storeValue(*type, _varDecl.location(), true);
if (_varDecl.immutable())
ImmutableItem(m_context, _varDecl).storeValue(*type, _varDecl.location(), true);
else
StorageItem(m_context, _varDecl).storeValue(*type, _varDecl.location(), true);
}
void ExpressionCompiler::appendConstStateVariableAccessor(VariableDeclaration const& _varDecl)
+1
View File
@@ -183,6 +183,7 @@ void ImmutableItem::setToZero(SourceLocation const&, bool) const
StorageItem::StorageItem(CompilerContext& _compilerContext, VariableDeclaration const& _declaration):
StorageItem(_compilerContext, *_declaration.annotation().type)
{
solAssert(!_declaration.immutable(), "");
auto const& location = m_context.storageLocationOfVariable(_declaration);
m_context << location.first << u256(location.second);
}