Test for binding user type operator to error

This commit is contained in:
wechman 2022-08-08 14:14:39 +02:00
parent 1218b207ef
commit f6543f772d
2 changed files with 12 additions and 19 deletions

View File

@ -1750,25 +1750,6 @@ bool TypeChecker::visit(UnaryOperation const& _operation)
solAssert(!builtinResult || !userDefinedOperatorResult);
if (userDefinedOperatorResult)
{
Type const* normalizedSubExprType = subExprType;
Type const* normalizedParameterType = userDefinedFunctionType->parameterTypes().front();
if (auto const* subExprReference = dynamic_cast<ReferenceType const*>(normalizedSubExprType))
normalizedSubExprType = TypeProvider::withLocationIfReference(subExprReference->location(), normalizedSubExprType);
if (auto const* parameterReferenceType = dynamic_cast<ReferenceType const*>(normalizedParameterType))
normalizedParameterType = TypeProvider::withLocationIfReference(parameterReferenceType->location(), normalizedParameterType);
if (*normalizedSubExprType != *normalizedParameterType)
{
m_errorReporter.typeError(
7983_error,
_operation.location(),
"User defined operator " + string(TokenTraits::toString(_operation.getOperator())) +
" needs a value of type " +
userDefinedFunctionType->parameterTypes().front()->humanReadableName() + "."
);
}
_operation.annotation().type = subExprType;
}
else if (builtinResult)

View File

@ -0,0 +1,12 @@
type Int is int16;
using {f as +} for IntError;
error IntError();
function f(Int _a, Int _b) pure returns (Int) {
return Int.wrap(0);
}
// ----
// TypeError 5172: (39-47): Name has to refer to a user-defined value type, struct, enum or contract.