mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Prepare code to output errors returned by isImplicitlyConvertibleTo()
This commit is contained in:
parent
ca9cced4b2
commit
de98e38b78
@ -139,14 +139,21 @@ TypePointers TypeChecker::typeCheckABIDecodeAndRetrieveReturnType(FunctionCall c
|
|||||||
toString(arguments.size()) +
|
toString(arguments.size()) +
|
||||||
" were provided."
|
" were provided."
|
||||||
);
|
);
|
||||||
if (arguments.size() >= 1 && !type(*arguments.front())->isImplicitlyConvertibleTo(ArrayType::bytesMemory()))
|
|
||||||
m_errorReporter.typeError(
|
if (arguments.size() >= 1)
|
||||||
|
{
|
||||||
|
BoolResult result = type(*arguments.front())->isImplicitlyConvertibleTo(ArrayType::bytesMemory());
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
m_errorReporter.typeErrorConcatenateDescriptions(
|
||||||
arguments.front()->location(),
|
arguments.front()->location(),
|
||||||
"Invalid type for argument in function call. "
|
"Invalid type for argument in function call. "
|
||||||
"Invalid implicit conversion from " +
|
"Invalid implicit conversion from " +
|
||||||
type(*arguments.front())->toString() +
|
type(*arguments.front())->toString() +
|
||||||
" to bytes memory requested."
|
" to bytes memory requested.",
|
||||||
|
result.message()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (arguments.size() < 2)
|
if (arguments.size() < 2)
|
||||||
return {};
|
return {};
|
||||||
@ -262,18 +269,22 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < std::min(arguments->size(), parameterTypes.size()); ++i)
|
for (size_t i = 0; i < std::min(arguments->size(), parameterTypes.size()); ++i)
|
||||||
if (!type(*(*arguments)[i])->isImplicitlyConvertibleTo(*parameterTypes[i]))
|
{
|
||||||
m_errorReporter.typeError(
|
BoolResult result = type(*(*arguments)[i])->isImplicitlyConvertibleTo(*parameterTypes[i]);
|
||||||
|
if (!result)
|
||||||
|
m_errorReporter.typeErrorConcatenateDescriptions(
|
||||||
(*arguments)[i]->location(),
|
(*arguments)[i]->location(),
|
||||||
"Invalid type for argument in constructor call. "
|
"Invalid type for argument in constructor call. "
|
||||||
"Invalid implicit conversion from " +
|
"Invalid implicit conversion from " +
|
||||||
type(*(*arguments)[i])->toString() +
|
type(*(*arguments)[i])->toString() +
|
||||||
" to " +
|
" to " +
|
||||||
parameterTypes[i]->toString() +
|
parameterTypes[i]->toString() +
|
||||||
" requested."
|
" requested.",
|
||||||
|
result.message()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TypeChecker::endVisit(UsingForDirective const& _usingFor)
|
void TypeChecker::endVisit(UsingForDirective const& _usingFor)
|
||||||
{
|
{
|
||||||
@ -566,17 +577,21 @@ void TypeChecker::visitManually(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < arguments.size(); ++i)
|
for (size_t i = 0; i < arguments.size(); ++i)
|
||||||
if (!type(*arguments[i])->isImplicitlyConvertibleTo(*type(*(*parameters)[i])))
|
{
|
||||||
m_errorReporter.typeError(
|
BoolResult result = type(*arguments[i])->isImplicitlyConvertibleTo(*type(*(*parameters)[i]));
|
||||||
|
if (!result)
|
||||||
|
m_errorReporter.typeErrorConcatenateDescriptions(
|
||||||
arguments[i]->location(),
|
arguments[i]->location(),
|
||||||
"Invalid type for argument in modifier invocation. "
|
"Invalid type for argument in modifier invocation. "
|
||||||
"Invalid implicit conversion from " +
|
"Invalid implicit conversion from " +
|
||||||
type(*arguments[i])->toString() +
|
type(*arguments[i])->toString() +
|
||||||
" to " +
|
" to " +
|
||||||
type(*(*parameters)[i])->toString() +
|
type(*(*parameters)[i])->toString() +
|
||||||
" requested."
|
" requested.",
|
||||||
|
result.message()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool TypeChecker::visit(EventDefinition const& _eventDef)
|
bool TypeChecker::visit(EventDefinition const& _eventDef)
|
||||||
{
|
{
|
||||||
@ -767,29 +782,34 @@ void TypeChecker::endVisit(Return const& _return)
|
|||||||
{
|
{
|
||||||
if (tupleType->components().size() != params->parameters().size())
|
if (tupleType->components().size() != params->parameters().size())
|
||||||
m_errorReporter.typeError(_return.location(), "Different number of arguments in return statement than in returns declaration.");
|
m_errorReporter.typeError(_return.location(), "Different number of arguments in return statement than in returns declaration.");
|
||||||
else if (!tupleType->isImplicitlyConvertibleTo(TupleType(returnTypes)))
|
else
|
||||||
m_errorReporter.typeError(
|
{
|
||||||
|
BoolResult result = tupleType->isImplicitlyConvertibleTo(TupleType(returnTypes));
|
||||||
|
if (!result)
|
||||||
|
m_errorReporter.typeErrorConcatenateDescriptions(
|
||||||
_return.expression()->location(),
|
_return.expression()->location(),
|
||||||
"Return argument type " +
|
"Return argument type " +
|
||||||
type(*_return.expression())->toString() +
|
type(*_return.expression())->toString() +
|
||||||
" is not implicitly convertible to expected type " +
|
" is not implicitly convertible to expected type " +
|
||||||
TupleType(returnTypes).toString(false) +
|
TupleType(returnTypes).toString(false) + ".",
|
||||||
"."
|
result.message()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (params->parameters().size() != 1)
|
else if (params->parameters().size() != 1)
|
||||||
m_errorReporter.typeError(_return.location(), "Different number of arguments in return statement than in returns declaration.");
|
m_errorReporter.typeError(_return.location(), "Different number of arguments in return statement than in returns declaration.");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TypePointer const& expected = type(*params->parameters().front());
|
TypePointer const& expected = type(*params->parameters().front());
|
||||||
if (!type(*_return.expression())->isImplicitlyConvertibleTo(*expected))
|
BoolResult result = type(*_return.expression())->isImplicitlyConvertibleTo(*expected);
|
||||||
m_errorReporter.typeError(
|
if (!result)
|
||||||
|
m_errorReporter.typeErrorConcatenateDescriptions(
|
||||||
_return.expression()->location(),
|
_return.expression()->location(),
|
||||||
"Return argument type " +
|
"Return argument type " +
|
||||||
type(*_return.expression())->toString() +
|
type(*_return.expression())->toString() +
|
||||||
" is not implicitly convertible to expected type (type of first return variable) " +
|
" is not implicitly convertible to expected type (type of first return variable) " +
|
||||||
expected->toString() +
|
expected->toString() + ".",
|
||||||
"."
|
result.message()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -981,7 +1001,8 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var.accept(*this);
|
var.accept(*this);
|
||||||
if (!valueComponentType->isImplicitlyConvertibleTo(*var.annotation().type))
|
BoolResult result = valueComponentType->isImplicitlyConvertibleTo(*var.annotation().type);
|
||||||
|
if (!result)
|
||||||
{
|
{
|
||||||
auto errorMsg = "Type " +
|
auto errorMsg = "Type " +
|
||||||
valueComponentType->toString() +
|
valueComponentType->toString() +
|
||||||
@ -1008,7 +1029,11 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_errorReporter.typeError(_statement.location(), errorMsg + ".");
|
m_errorReporter.typeErrorConcatenateDescriptions(
|
||||||
|
_statement.location(),
|
||||||
|
errorMsg + ".",
|
||||||
|
result.message()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user