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,8 +1710,7 @@ Type const* TypeChecker::typeCheckTypeConversionAndRetrieveReturnType(
|
|||||||
{
|
{
|
||||||
if (auto argArrayType = dynamic_cast<ArrayType const*>(argType))
|
if (auto argArrayType = dynamic_cast<ArrayType const*>(argType))
|
||||||
{
|
{
|
||||||
auto resultArrayType = dynamic_cast<ArrayType const*>(resultType);
|
if (auto resultArrayType = dynamic_cast<ArrayType const*>(resultType))
|
||||||
solAssert(!!resultArrayType, "");
|
|
||||||
solAssert(
|
solAssert(
|
||||||
argArrayType->location() != DataLocation::Storage ||
|
argArrayType->location() != DataLocation::Storage ||
|
||||||
(
|
(
|
||||||
@ -1723,6 +1722,11 @@ Type const* TypeChecker::typeCheckTypeConversionAndRetrieveReturnType(
|
|||||||
),
|
),
|
||||||
"Invalid explicit conversion to storage type."
|
"Invalid explicit conversion to storage type."
|
||||||
);
|
);
|
||||||
|
else
|
||||||
|
solAssert(
|
||||||
|
argArrayType->isByteArray() && !argArrayType->isString() && resultType->category() == Type::Category::FixedBytes,
|
||||||
|
""
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1570,9 +1570,9 @@ BoolResult ArrayType::isExplicitlyConvertibleTo(Type const& _convertTo) const
|
|||||||
{
|
{
|
||||||
if (isImplicitlyConvertibleTo(_convertTo))
|
if (isImplicitlyConvertibleTo(_convertTo))
|
||||||
return true;
|
return true;
|
||||||
// allow conversion bytes <-> string
|
// allow conversion bytes <-> string and bytes -> bytesNN
|
||||||
if (_convertTo.category() != category())
|
if (_convertTo.category() != category())
|
||||||
return false;
|
return isByteArray() && !isString() && _convertTo.category() == Type::Category::FixedBytes;
|
||||||
auto& convertTo = dynamic_cast<ArrayType const&>(_convertTo);
|
auto& convertTo = dynamic_cast<ArrayType const&>(_convertTo);
|
||||||
if (convertTo.location() != location())
|
if (convertTo.location() != location())
|
||||||
return false;
|
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
|
string ArraySliceType::richIdentifier() const
|
||||||
{
|
{
|
||||||
return m_arrayType.richIdentifier() + "_slice";
|
return m_arrayType.richIdentifier() + "_slice";
|
||||||
|
@ -889,6 +889,7 @@ public:
|
|||||||
Category category() const override { return Category::ArraySlice; }
|
Category category() const override { return Category::ArraySlice; }
|
||||||
|
|
||||||
BoolResult isImplicitlyConvertibleTo(Type const& _other) const override;
|
BoolResult isImplicitlyConvertibleTo(Type const& _other) const override;
|
||||||
|
BoolResult isExplicitlyConvertibleTo(Type const& _convertTo) const override;
|
||||||
std::string richIdentifier() const override;
|
std::string richIdentifier() const override;
|
||||||
bool operator==(Type const& _other) const override;
|
bool operator==(Type const& _other) const override;
|
||||||
unsigned calldataEncodedSize(bool) const override { solAssert(false, ""); }
|
unsigned calldataEncodedSize(bool) const override { solAssert(false, ""); }
|
||||||
|
Loading…
Reference in New Issue
Block a user