mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
YulUtilFunctions: convertionFunction() to also handle array string/memory casts.
This commit is contained in:
parent
b1e43833c7
commit
5d7a370248
@ -1469,22 +1469,34 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
|
|||||||
break;
|
break;
|
||||||
case Type::Category::Array:
|
case Type::Category::Array:
|
||||||
{
|
{
|
||||||
bool equal = _from == _to;
|
if (_from == _to)
|
||||||
|
body = "converted := value";
|
||||||
if (!equal)
|
else
|
||||||
{
|
{
|
||||||
ArrayType const& from = dynamic_cast<decltype(from)>(_from);
|
ArrayType const& from = dynamic_cast<decltype(from)>(_from);
|
||||||
ArrayType const& to = dynamic_cast<decltype(to)>(_to);
|
ArrayType const& to = dynamic_cast<decltype(to)>(_to);
|
||||||
|
|
||||||
if (*from.mobileType() == *to.mobileType())
|
switch (to.location())
|
||||||
equal = true;
|
{
|
||||||
}
|
case DataLocation::Storage:
|
||||||
|
// Other cases are done explicitly in LValue::storeValue, and only possible by assignment.
|
||||||
if (equal)
|
solAssert(
|
||||||
|
(to.isPointer() || (from.isByteArray() && to.isByteArray())) &&
|
||||||
|
from.location() == DataLocation::Storage,
|
||||||
|
"Invalid conversion to storage type."
|
||||||
|
);
|
||||||
body = "converted := value";
|
body = "converted := value";
|
||||||
else
|
break;
|
||||||
solUnimplementedAssert(false, "Array conversion not implemented.");
|
case DataLocation::Memory:
|
||||||
|
// Copy the array to a free position in memory, unless it is already in memory.
|
||||||
|
solUnimplementedAssert(from.location() == DataLocation::Memory, "Not implemented yet.");
|
||||||
|
body = "converted := value";
|
||||||
|
break;
|
||||||
|
case DataLocation::CallData:
|
||||||
|
solUnimplemented("Conversion of calldata types not yet implemented.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Type::Category::Struct:
|
case Type::Category::Struct:
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
contract C {
|
||||||
|
function f(string memory s) public pure returns (bytes memory t) {
|
||||||
|
t = bytes(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f(string): 32, 5, "Hello" -> 32, 5, "Hello"
|
Loading…
Reference in New Issue
Block a user