mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Update code after review
This commit is contained in:
parent
4ed523c4e8
commit
0f55a4d671
@ -68,8 +68,10 @@ bool TypeChecker::typeSupportedByOldABIEncoder(Type const& _type, bool _isLibrar
|
||||
}
|
||||
if (_type.category() == Type::Category::InlineArray)
|
||||
{
|
||||
auto const& inlineArray = dynamic_cast<InlineArrayType const&>(_type);
|
||||
return typeSupportedByOldABIEncoder(*inlineArray.mobileType(), _isLibraryCall);
|
||||
auto const& mobileType = dynamic_cast<InlineArrayType const&>(_type).mobileType();
|
||||
if (!mobileType)
|
||||
return false;
|
||||
return typeSupportedByOldABIEncoder(*mobileType, _isLibraryCall);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1208,7 +1210,7 @@ void TypeChecker::endVisit(Return const& _return)
|
||||
_return.expression()->location(),
|
||||
"Return argument type " +
|
||||
type(*_return.expression())->toString() +
|
||||
" is not implicitly convertible to expected type " +
|
||||
" is not implicitly convertible to expected type (type of first return variable) " +
|
||||
TupleType(returnTypes).toString(false) + ".",
|
||||
result.message()
|
||||
);
|
||||
@ -3259,13 +3261,12 @@ bool TypeChecker::visit(IndexAccess const& _access)
|
||||
}
|
||||
case Type::Category::InlineArray:
|
||||
{
|
||||
InlineArrayType const& actualType = dynamic_cast<InlineArrayType const&>(*baseType);
|
||||
if (!index)
|
||||
m_errorReporter.typeError(5093_error, _access.location(), "Index expression cannot be omitted.");
|
||||
else
|
||||
expectType(*index, *TypeProvider::uint256());
|
||||
|
||||
resultType = actualType.componentsCommonMobileType();
|
||||
resultType = dynamic_cast<InlineArrayType const&>(*baseType).componentsCommonMobileType();
|
||||
break;
|
||||
}
|
||||
case Type::Category::Mapping:
|
||||
|
||||
@ -316,15 +316,6 @@ Type const* Type::fullEncodingType(bool _inLibraryCall, bool _encoderV2, bool) c
|
||||
return encodingType;
|
||||
Type const* baseType = encodingType;
|
||||
|
||||
if (auto const inlineArray = dynamic_cast<InlineArrayType const*>(baseType))
|
||||
{
|
||||
baseType = TypeProvider::array(
|
||||
DataLocation::Memory,
|
||||
inlineArray->componentsCommonMobileType(),
|
||||
inlineArray->components().size()
|
||||
);
|
||||
}
|
||||
|
||||
while (auto const* arrayType = dynamic_cast<ArrayType const*>(baseType))
|
||||
{
|
||||
baseType = arrayType->baseType();
|
||||
@ -2714,26 +2705,25 @@ BoolResult InlineArrayType::isImplicitlyConvertibleTo(Type const& _other) const
|
||||
|
||||
if (!arrayType || arrayType->isByteArrayOrString())
|
||||
return BoolResult::err("Array literal can not be converted to byte array or string.");
|
||||
else
|
||||
|
||||
if (!arrayType->isDynamicallySized() && arrayType->length() != components().size())
|
||||
return BoolResult::err(
|
||||
"Number of components in array literal (" + to_string(components().size()) + ") " +
|
||||
"does not match array size (" + to_string(arrayType->length().convert_to<unsigned>()) + ")."
|
||||
);
|
||||
|
||||
for (Type const* c: components())
|
||||
{
|
||||
if (!arrayType->isDynamicallySized() && arrayType->length() != components().size())
|
||||
BoolResult result = c->isImplicitlyConvertibleTo(*arrayType->baseType());
|
||||
if (!result)
|
||||
return BoolResult::err(
|
||||
"Number of components in array literal (" + to_string(components().size()) + ") " +
|
||||
"does not match array size (" + to_string(arrayType->length().convert_to<unsigned>()) + ").");
|
||||
|
||||
for (Type const* c: components())
|
||||
{
|
||||
BoolResult result = c->isImplicitlyConvertibleTo(*arrayType->baseType());
|
||||
if (!result)
|
||||
if (!result)
|
||||
return BoolResult::err(
|
||||
"Invalid conversion from " + c->toString(false) +
|
||||
" to " + arrayType->baseType()->toString(false) + "."
|
||||
+ (result.message().empty() ? "" : " ") + result.message() );
|
||||
}
|
||||
|
||||
return true;
|
||||
"Invalid conversion from " + c->toString(false) +
|
||||
" to " + arrayType->baseType()->toString(false) + "." +
|
||||
(result.message().empty() ? "" : " ") + result.message()
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
string InlineArrayType::richIdentifier() const
|
||||
@ -2744,8 +2734,17 @@ string InlineArrayType::richIdentifier() const
|
||||
bool InlineArrayType::operator==(Type const& _other) const
|
||||
{
|
||||
if (auto inlineArrayType = dynamic_cast<InlineArrayType const*>(&_other))
|
||||
// TODO: raise issue - do not compare by pointer for tuple type
|
||||
return components() == inlineArrayType->components();
|
||||
{
|
||||
std::vector<Type const*> const& otherComponents = inlineArrayType->components();
|
||||
if (m_components.size() != otherComponents.size())
|
||||
return false;
|
||||
|
||||
for (unsigned i = 0; i < m_components.size(); ++i)
|
||||
if (!(*m_components[i] == *otherComponents[i]))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
@ -2753,11 +2752,8 @@ bool InlineArrayType::operator==(Type const& _other) const
|
||||
string InlineArrayType::toString(bool _short) const
|
||||
{
|
||||
vector<string> result;
|
||||
|
||||
for (auto const& t: components())
|
||||
result.push_back(t->toString(_short));
|
||||
|
||||
// TODO joinHumanReadable - is it fine to have a space here?
|
||||
return "inline_array(" + util::joinHumanReadable(result) + ")";
|
||||
}
|
||||
|
||||
@ -2768,12 +2764,12 @@ u256 InlineArrayType::storageSize() const
|
||||
|
||||
Type const* InlineArrayType::mobileType() const
|
||||
{
|
||||
return TypeProvider::array(
|
||||
DataLocation::Memory,
|
||||
componentsCommonMobileType(),
|
||||
components().size()
|
||||
);
|
||||
}
|
||||
Type const* baseType = componentsCommonMobileType();
|
||||
return
|
||||
baseType ?
|
||||
TypeProvider::array(DataLocation::Memory, baseType, components().size()) :
|
||||
nullptr;
|
||||
}
|
||||
|
||||
Type const* InlineArrayType::componentsCommonMobileType() const
|
||||
{
|
||||
|
||||
@ -293,7 +293,8 @@ string ABIFunctions::abiEncodingFunction(
|
||||
return abiEncodingFunctionInlineArray(
|
||||
dynamic_cast<InlineArrayType const&>(_from),
|
||||
dynamic_cast<ArrayType const&>(_to),
|
||||
_options);
|
||||
_options
|
||||
);
|
||||
|
||||
}
|
||||
else if (auto toArray = dynamic_cast<ArrayType const*>(&to))
|
||||
|
||||
@ -2,4 +2,4 @@ contract test {
|
||||
function f() public returns (uint256 r, uint8) { return ((12, "")); }
|
||||
}
|
||||
// ----
|
||||
// TypeError 5992: (76-86): Return argument type tuple(int_const 12,literal_string "") is not implicitly convertible to expected type tuple(uint256,uint8).
|
||||
// TypeError 5992: (76-86): Return argument type tuple(int_const 12,literal_string "") is not implicitly convertible to expected type (type of first return variable) tuple(uint256,uint8).
|
||||
|
||||
Loading…
Reference in New Issue
Block a user