diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index 88f3e7263..98a8fd294 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -241,6 +241,10 @@ void IRGeneratorForStatements::initializeStateVar(VariableDeclaration const& _va return; _varDecl.value()->accept(*this); + + Type const* rightIntermediateType = _varDecl.value()->annotation().type->closestTemporaryType(_varDecl.type()); + solAssert(rightIntermediateType, ""); + IRVariable value = convert(*_varDecl.value(), *rightIntermediateType); writeToLValue( _varDecl.immutable() ? IRLValue{*_varDecl.annotation().type, IRLValue::Immutable{&_varDecl}} : @@ -248,7 +252,7 @@ void IRGeneratorForStatements::initializeStateVar(VariableDeclaration const& _va util::toCompactHexWithPrefix(m_context.storageLocationOfStateVariable(_varDecl).first), m_context.storageLocationOfStateVariable(_varDecl).second }}, - *_varDecl.value() + value ); } catch (langutil::UnimplementedFeatureError const& _error) diff --git a/test/libsolidity/semanticTests/array/copying/bytes_storage_to_memory.sol b/test/libsolidity/semanticTests/array/copying/bytes_storage_to_memory.sol index 13932a2cc..2e39b1405 100644 --- a/test/libsolidity/semanticTests/array/copying/bytes_storage_to_memory.sol +++ b/test/libsolidity/semanticTests/array/copying/bytes_storage_to_memory.sol @@ -5,5 +5,7 @@ contract C { return data[0]; } } +// ==== +// compileViaYul: also // ---- // f() -> "a" diff --git a/test/libsolidity/semanticTests/array/inline_array_storage_to_memory_conversion_strings.sol b/test/libsolidity/semanticTests/array/inline_array_storage_to_memory_conversion_strings.sol index fa9f24a7a..a6ad1e32e 100644 --- a/test/libsolidity/semanticTests/array/inline_array_storage_to_memory_conversion_strings.sol +++ b/test/libsolidity/semanticTests/array/inline_array_storage_to_memory_conversion_strings.sol @@ -8,5 +8,7 @@ contract C { } } +// ==== +// compileViaYul: also // ---- // f() -> 0x40, 0x80, 0x3, "ray", 0x2, "mi"