mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #8574 from ethereum/immutableAssignAtDecl
Properly handle assignments of immutables at declaration.
This commit is contained in:
commit
c8f0629e94
@ -550,7 +550,7 @@ void ContractCompiler::initializeStateVariables(ContractDefinition const& _contr
|
|||||||
{
|
{
|
||||||
solAssert(!_contract.isLibrary(), "Tried to initialize state variables of library.");
|
solAssert(!_contract.isLibrary(), "Tried to initialize state variables of library.");
|
||||||
for (VariableDeclaration const* variable: _contract.stateVariables())
|
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);
|
ExpressionCompiler(m_context, m_optimiserSettings.runOrderLiterals).appendStateVariableInitialization(*variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,10 @@ void ExpressionCompiler::appendStateVariableInitialization(VariableDeclaration c
|
|||||||
utils().convertType(*type, *_varDecl.annotation().type);
|
utils().convertType(*type, *_varDecl.annotation().type);
|
||||||
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)
|
void ExpressionCompiler::appendConstStateVariableAccessor(VariableDeclaration const& _varDecl)
|
||||||
|
@ -183,6 +183,7 @@ void ImmutableItem::setToZero(SourceLocation const&, bool) const
|
|||||||
StorageItem::StorageItem(CompilerContext& _compilerContext, VariableDeclaration const& _declaration):
|
StorageItem::StorageItem(CompilerContext& _compilerContext, VariableDeclaration const& _declaration):
|
||||||
StorageItem(_compilerContext, *_declaration.annotation().type)
|
StorageItem(_compilerContext, *_declaration.annotation().type)
|
||||||
{
|
{
|
||||||
|
solAssert(!_declaration.immutable(), "");
|
||||||
auto const& location = m_context.storageLocationOfVariable(_declaration);
|
auto const& location = m_context.storageLocationOfVariable(_declaration);
|
||||||
m_context << location.first << u256(location.second);
|
m_context << location.first << u256(location.second);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
contract A {
|
||||||
|
uint8 immutable a = 2;
|
||||||
|
function f() public view returns (uint) {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// f() -> 2
|
Loading…
Reference in New Issue
Block a user