1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 12:02:21 +02:00

Better error messages for attempted op overload calls on interfaces

This commit is contained in:
Brian Fiete 2020-01-29 16:26:52 -08:00
parent f874535a13
commit a75cc2d8f9

View file

@ -16329,7 +16329,7 @@ void BfExprEvaluator::PerformUnaryOperation_OnResult(BfExpression* unaryOpExpr,
BfResolvedArg resolvedArg; BfResolvedArg resolvedArg;
resolvedArg.mTypedValue = mResult; resolvedArg.mTypedValue = mResult;
args.push_back(resolvedArg); args.push_back(resolvedArg);
BfMethodMatcher methodMatcher(opToken, mModule, "", args, NULL); BfMethodMatcher methodMatcher(opToken, mModule, "", args, NULL);
BfBaseClassWalker baseClassWalker(mResult.mType, NULL, mModule); BfBaseClassWalker baseClassWalker(mResult.mType, NULL, mModule);
BfUnaryOp findOp = unaryOp; BfUnaryOp findOp = unaryOp;
@ -16804,7 +16804,18 @@ void BfExprEvaluator::PerformUnaryOperation_OnResult(BfExpression* unaryOpExpr,
if (numericFail) if (numericFail)
{ {
mModule->Fail("Operator can only be used on numeric types", opToken); if (mResult.mType->IsInterface())
{
mModule->Fail(
StrFormat("Operator '%s' cannot be used on interface '%s'. Consider rewriting using generics and use this interface as a generic constraint.",
BfTokenToString(opToken->mToken), mModule->TypeToString(mResult.mType).c_str()), opToken);
}
else
{
mModule->Fail(
StrFormat("Operator '%s' cannot be used because type '%s' is neither a numeric type nor does it define an applicable operator overload",
BfTokenToString(opToken->mToken), mModule->TypeToString(mResult.mType).c_str()), opToken);
}
mResult = BfTypedValue(); mResult = BfTypedValue();
} }
@ -17343,8 +17354,18 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
mModule->Fail(StrFormat("Cannot perform binary operation '%s' between types '%s' and '%s'", mModule->Fail(StrFormat("Cannot perform binary operation '%s' between types '%s' and '%s'",
BfGetOpName(binaryOp), mModule->TypeToString(leftValue.mType).c_str(), mModule->TypeToString(rightValue.mType).c_str()), opToken); BfGetOpName(binaryOp), mModule->TypeToString(leftValue.mType).c_str(), mModule->TypeToString(rightValue.mType).c_str()), opToken);
else else
mModule->Fail(StrFormat("Cannot perform binary operation '%s' between two instances of type '%s'", {
BfGetOpName(binaryOp), mModule->TypeToString(leftValue.mType).c_str()), opToken); if (leftValue.mType->IsInterface())
{
mModule->Fail(StrFormat("Cannot perform binary operation '%s' between two instances of interface '%s'. Consider rewriting using generics and use this interface as a generic constraint.",
BfGetOpName(binaryOp), mModule->TypeToString(leftValue.mType).c_str()), opToken);
}
else
{
mModule->Fail(StrFormat("Cannot perform binary operation '%s' between two instances of type '%s'",
BfGetOpName(binaryOp), mModule->TypeToString(leftValue.mType).c_str()), opToken);
}
}
} }
else else
mModule->Fail(StrFormat("Cannot perform binary operation '%s'", BfGetOpName(binaryOp)), opToken); mModule->Fail(StrFormat("Cannot perform binary operation '%s'", BfGetOpName(binaryOp)), opToken);