mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allowing conversion from bytes to bytesNN in type checker.
This commit is contained in:
parent
15decd2413
commit
b40c3bcc32
@ -1710,19 +1710,23 @@ Type const* TypeChecker::typeCheckTypeConversionAndRetrieveReturnType(
|
||||
{
|
||||
if (auto argArrayType = dynamic_cast<ArrayType const*>(argType))
|
||||
{
|
||||
auto resultArrayType = dynamic_cast<ArrayType const*>(resultType);
|
||||
solAssert(!!resultArrayType, "");
|
||||
solAssert(
|
||||
argArrayType->location() != DataLocation::Storage ||
|
||||
(
|
||||
if (auto resultArrayType = dynamic_cast<ArrayType const*>(resultType))
|
||||
solAssert(
|
||||
argArrayType->location() != DataLocation::Storage ||
|
||||
(
|
||||
resultArrayType->isPointer() ||
|
||||
(argArrayType->isByteArray() && resultArrayType->isByteArray())
|
||||
) &&
|
||||
resultArrayType->location() == DataLocation::Storage
|
||||
),
|
||||
"Invalid explicit conversion to storage type."
|
||||
);
|
||||
(
|
||||
resultArrayType->isPointer() ||
|
||||
(argArrayType->isByteArray() && resultArrayType->isByteArray())
|
||||
) &&
|
||||
resultArrayType->location() == DataLocation::Storage
|
||||
),
|
||||
"Invalid explicit conversion to storage type."
|
||||
);
|
||||
else
|
||||
solAssert(
|
||||
argArrayType->isByteArray() && !argArrayType->isString() && resultType->category() == Type::Category::FixedBytes,
|
||||
""
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1570,9 +1570,9 @@ BoolResult ArrayType::isExplicitlyConvertibleTo(Type const& _convertTo) const
|
||||
{
|
||||
if (isImplicitlyConvertibleTo(_convertTo))
|
||||
return true;
|
||||
// allow conversion bytes <-> string
|
||||
// allow conversion bytes <-> string and bytes -> bytesNN
|
||||
if (_convertTo.category() != category())
|
||||
return false;
|
||||
return isByteArray() && !isString() && _convertTo.category() == Type::Category::FixedBytes;
|
||||
auto& convertTo = dynamic_cast<ArrayType const&>(_convertTo);
|
||||
if (convertTo.location() != location())
|
||||
return false;
|
||||
@ -1929,6 +1929,13 @@ BoolResult ArraySliceType::isImplicitlyConvertibleTo(Type const& _other) const
|
||||
);
|
||||
}
|
||||
|
||||
BoolResult ArraySliceType::isExplicitlyConvertibleTo(Type const& _convertTo) const
|
||||
{
|
||||
return
|
||||
isImplicitlyConvertibleTo(_convertTo) ||
|
||||
m_arrayType.isExplicitlyConvertibleTo(_convertTo);
|
||||
}
|
||||
|
||||
string ArraySliceType::richIdentifier() const
|
||||
{
|
||||
return m_arrayType.richIdentifier() + "_slice";
|
||||
|
@ -889,6 +889,7 @@ public:
|
||||
Category category() const override { return Category::ArraySlice; }
|
||||
|
||||
BoolResult isImplicitlyConvertibleTo(Type const& _other) const override;
|
||||
BoolResult isExplicitlyConvertibleTo(Type const& _convertTo) const override;
|
||||
std::string richIdentifier() const override;
|
||||
bool operator==(Type const& _other) const override;
|
||||
unsigned calldataEncodedSize(bool) const override { solAssert(false, ""); }
|
||||
|
Loading…
Reference in New Issue
Block a user