mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Test for binding user type operator to error
This commit is contained in:
parent
1218b207ef
commit
f6543f772d
@ -1750,25 +1750,6 @@ bool TypeChecker::visit(UnaryOperation const& _operation)
|
|||||||
solAssert(!builtinResult || !userDefinedOperatorResult);
|
solAssert(!builtinResult || !userDefinedOperatorResult);
|
||||||
if (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;
|
_operation.annotation().type = subExprType;
|
||||||
}
|
}
|
||||||
else if (builtinResult)
|
else if (builtinResult)
|
||||||
|
@ -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.
|
Loading…
Reference in New Issue
Block a user