[Sol->Yul] Implementing conversion from calldata slices to memory arrays.

Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
This commit is contained in:
Djordje Mijovic 2020-12-11 11:07:22 +01:00
parent b99a74fb34
commit 8aa4568b10
2 changed files with 12 additions and 9 deletions

View File

@ -2074,13 +2074,13 @@ std::unique_ptr<ReferenceType> ArrayType::copyForLocation(DataLocation _location
BoolResult ArraySliceType::isImplicitlyConvertibleTo(Type const& _other) const
{
if (
m_arrayType.dataStoredIn(DataLocation::CallData) &&
m_arrayType.isDynamicallySized() &&
m_arrayType.isImplicitlyConvertibleTo(_other)
)
return true;
return (*this) == _other;
return
(*this) == _other ||
(
m_arrayType.dataStoredIn(DataLocation::CallData) &&
m_arrayType.isDynamicallySized() &&
m_arrayType.isImplicitlyConvertibleTo(_other)
);
}
string ArraySliceType::richIdentifier() const

View File

@ -2852,8 +2852,8 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
solAssert(_from.dataStoredIn(DataLocation::CallData), "");
solAssert(_to.category() == Type::Category::Array, "");
ArraySliceType const& fromType = dynamic_cast<ArraySliceType const&>(_from);
ArrayType const& targetType = dynamic_cast<ArrayType const&>(_to);
auto const& fromType = dynamic_cast<ArraySliceType const&>(_from);
auto const& targetType = dynamic_cast<ArrayType const&>(_to);
solAssert(!fromType.arrayType().baseType()->isDynamicallyEncoded(), "");
solAssert(
@ -2861,6 +2861,9 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
"Converting arrays of different type is not possible"
);
if (!targetType.dataStoredIn(DataLocation::CallData))
return arrayConversionFunction(fromType.arrayType(), targetType);
string const functionName =
"convert_" +
_from.identifier() +