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

@ -16804,7 +16804,18 @@ void BfExprEvaluator::PerformUnaryOperation_OnResult(BfExpression* unaryOpExpr,
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();
}
@ -17343,9 +17354,19 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
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);
else
{
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
mModule->Fail(StrFormat("Cannot perform binary operation '%s'", BfGetOpName(binaryOp)), opToken);
};