Changed instaces of isByteArrayOrString() to isByteArray() where it's only supposed to return a True for Bytes Type

This commit is contained in:
nishant-sachdeva 2022-02-02 16:14:24 +05:30
parent 9043621747
commit cc6344c03c
6 changed files with 12 additions and 10 deletions

View File

@ -1791,7 +1791,7 @@ Type const* TypeChecker::typeCheckTypeConversionAndRetrieveReturnType(
);
else
solAssert(
argArrayType->isByteArrayOrString() && !argArrayType->isString() && resultType->category() == Type::Category::FixedBytes,
argArrayType->isByteArray() && resultType->category() == Type::Category::FixedBytes,
""
);
}

View File

@ -1530,7 +1530,7 @@ BoolResult ArrayType::isImplicitlyConvertibleTo(Type const& _convertTo) const
if (_convertTo.category() != category())
return false;
auto& convertTo = dynamic_cast<ArrayType const&>(_convertTo);
if (convertTo.isByteArrayOrString() != isByteArrayOrString() || convertTo.isString() != isString())
if (convertTo.isByteArray() != isByteArray() || convertTo.isString() != isString())
return false;
// memory/calldata to storage can be converted, but only to a direct storage reference
if (convertTo.location() == DataLocation::Storage && location() != DataLocation::Storage && convertTo.isPointer())
@ -1571,7 +1571,7 @@ BoolResult ArrayType::isExplicitlyConvertibleTo(Type const& _convertTo) const
return true;
// allow conversion bytes <-> string and bytes -> bytesNN
if (_convertTo.category() != category())
return isByteArrayOrString() && !isString() && _convertTo.category() == Type::Category::FixedBytes;
return isByteArray() && _convertTo.category() == Type::Category::FixedBytes;
auto& convertTo = dynamic_cast<ArrayType const&>(_convertTo);
if (convertTo.location() != location())
return false;
@ -1608,7 +1608,7 @@ bool ArrayType::operator==(Type const& _other) const
ArrayType const& other = dynamic_cast<ArrayType const&>(_other);
if (
!ReferenceType::operator==(other) ||
other.isByteArrayOrString() != isByteArrayOrString() ||
other.isByteArray() != isByteArray() ||
other.isString() != isString() ||
other.isDynamicallySized() != isDynamicallySized()
)

View File

@ -837,6 +837,8 @@ public:
BoolResult validForLocation(DataLocation _loc) const override;
/// @returns true if this is a byte array.
bool isByteArray() const { return m_arrayKind == ArrayKind::Bytes; }
/// @returns true if this is a byte array or a string
bool isByteArrayOrString() const { return m_arrayKind != ArrayKind::Ordinary; }
/// @returns true if this is a string

View File

@ -992,7 +992,7 @@ void CompilerUtils::convertType(
if (_targetType.category() == Type::Category::FixedBytes)
{
solAssert(
typeOnStack.isByteArrayOrString() && !typeOnStack.isString(),
typeOnStack.isByteArray(),
"Array types other than bytes not convertible to bytesNN."
);
solAssert(typeOnStack.isDynamicallySized());
@ -1119,7 +1119,7 @@ void CompilerUtils::convertType(
if (_targetType.category() == Type::Category::FixedBytes)
{
solAssert(
typeOnStack.arrayType().isByteArrayOrString() && !typeOnStack.arrayType().isString(),
typeOnStack.arrayType().isByteArray(),
"Array types other than bytes not convertible to bytesNN."
);
solAssert(typeOnStack.isDynamicallySized());

View File

@ -3216,7 +3216,7 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
auto const& fromType = dynamic_cast<ArraySliceType const&>(_from);
if (_to.category() == Type::Category::FixedBytes)
{
solAssert(fromType.arrayType().isByteArrayOrString(), "Array types other than bytes not convertible to bytesNN.");
solAssert(fromType.arrayType().isByteArray(), "Array types other than bytes not convertible to bytesNN.");
return bytesToFixedBytesConversionFunction(fromType.arrayType(), dynamic_cast<FixedBytesType const &>(_to));
}
solAssert(_to.category() == Type::Category::Array);
@ -3256,7 +3256,7 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
auto const& fromArrayType = dynamic_cast<ArrayType const&>(_from);
if (_to.category() == Type::Category::FixedBytes)
{
solAssert(fromArrayType.isByteArrayOrString(), "Array types other than bytes not convertible to bytesNN.");
solAssert(fromArrayType.isByteArray(), "Array types other than bytes not convertible to bytesNN.");
return bytesToFixedBytesConversionFunction(fromArrayType, dynamic_cast<FixedBytesType const &>(_to));
}
solAssert(_to.category() == Type::Category::Array, "");
@ -3460,7 +3460,7 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
string YulUtilFunctions::bytesToFixedBytesConversionFunction(ArrayType const& _from, FixedBytesType const& _to)
{
solAssert(_from.isByteArrayOrString() && !_from.isString(), "");
solAssert(_from.isByteArray(), "");
solAssert(_from.isDynamicallySized(), "");
string functionName = "convert_bytes_to_fixedbytes_from_" + _from.identifier() + "_to_" + _to.identifier();
return m_functionCollector.createFunction(functionName, [&](auto& _args, auto& _returnParams) {

View File

@ -96,7 +96,7 @@ SortPointer smtSort(frontend::Type const& _type)
auto sliceArrayType = dynamic_cast<ArraySliceType const*>(&_type);
ArrayType const* arrayType = sliceArrayType ? &sliceArrayType->arrayType() : dynamic_cast<ArrayType const*>(&_type);
if (
(arrayType && (arrayType->isString() || arrayType->isByteArrayOrString())) ||
(arrayType && arrayType->isByteArrayOrString()) ||
_type.category() == frontend::Type::Category::StringLiteral
)
tupleName = "bytes";