Fix binop bugs
This commit is contained in:
@@ -419,17 +419,48 @@ public sealed class TypeChecker
|
||||
{
|
||||
case BinaryOperatorSyntax.Equal:
|
||||
case BinaryOperatorSyntax.NotEqual:
|
||||
{
|
||||
var left = CheckExpression(expression.Left);
|
||||
if (left.Type is not NubIntType and not NubFloatType and not NubBoolType)
|
||||
{
|
||||
throw new TypeCheckerException(Diagnostic
|
||||
.Error("Equal and not equal operators must must be used with int, float or bool types")
|
||||
.At(expression.Left)
|
||||
.Build());
|
||||
}
|
||||
|
||||
var right = CheckExpression(expression.Right, left.Type);
|
||||
|
||||
return new BinaryExpressionNode(new NubBoolType(), left, op, right);
|
||||
}
|
||||
case BinaryOperatorSyntax.GreaterThan:
|
||||
case BinaryOperatorSyntax.GreaterThanOrEqual:
|
||||
case BinaryOperatorSyntax.LessThan:
|
||||
case BinaryOperatorSyntax.LessThanOrEqual:
|
||||
case BinaryOperatorSyntax.LogicalAnd:
|
||||
case BinaryOperatorSyntax.LogicalOr:
|
||||
{
|
||||
var left = CheckExpression(expression.Left);
|
||||
if (left.Type is not NubIntType and not NubFloatType)
|
||||
{
|
||||
throw new TypeCheckerException(Diagnostic.Error("Logical operators must must be used with int or float types").At(expression.Left).Build());
|
||||
throw new TypeCheckerException(Diagnostic
|
||||
.Error("Greater than and less than operators must must be used with int or float types")
|
||||
.At(expression.Left)
|
||||
.Build());
|
||||
}
|
||||
|
||||
var right = CheckExpression(expression.Right, left.Type);
|
||||
|
||||
return new BinaryExpressionNode(new NubBoolType(), left, op, right);
|
||||
}
|
||||
case BinaryOperatorSyntax.LogicalAnd:
|
||||
case BinaryOperatorSyntax.LogicalOr:
|
||||
{
|
||||
var left = CheckExpression(expression.Left);
|
||||
if (left.Type is not NubBoolType)
|
||||
{
|
||||
throw new TypeCheckerException(Diagnostic
|
||||
.Error("Logical and/or must must be used with bool types")
|
||||
.At(expression.Left)
|
||||
.Build());
|
||||
}
|
||||
|
||||
var right = CheckExpression(expression.Right, left.Type);
|
||||
@@ -445,7 +476,10 @@ public sealed class TypeChecker
|
||||
return new BinaryExpressionNode(left.Type, left, op, right);
|
||||
}
|
||||
|
||||
throw new TypeCheckerException(Diagnostic.Error("The plus operator must be used with int, float, cstring or string types").At(expression.Left).Build());
|
||||
throw new TypeCheckerException(Diagnostic
|
||||
.Error("The plus operator must be used with int, float, cstring or string types")
|
||||
.At(expression.Left)
|
||||
.Build());
|
||||
}
|
||||
case BinaryOperatorSyntax.Minus:
|
||||
case BinaryOperatorSyntax.Multiply:
|
||||
@@ -455,7 +489,10 @@ public sealed class TypeChecker
|
||||
var left = CheckExpression(expression.Left);
|
||||
if (left.Type is not NubIntType and not NubFloatType)
|
||||
{
|
||||
throw new TypeCheckerException(Diagnostic.Error("Math operators must be used with int or float types").At(expression.Left).Build());
|
||||
throw new TypeCheckerException(Diagnostic
|
||||
.Error("Math operators must be used with int or float types")
|
||||
.At(expression.Left)
|
||||
.Build());
|
||||
}
|
||||
|
||||
var right = CheckExpression(expression.Right, left.Type);
|
||||
@@ -471,7 +508,10 @@ public sealed class TypeChecker
|
||||
var left = CheckExpression(expression.Left);
|
||||
if (left.Type is not NubIntType)
|
||||
{
|
||||
throw new TypeCheckerException(Diagnostic.Error("Bitwise operators must be used with int types").At(expression.Left).Build());
|
||||
throw new TypeCheckerException(Diagnostic
|
||||
.Error("Bitwise operators must be used with int types")
|
||||
.At(expression.Left)
|
||||
.Build());
|
||||
}
|
||||
|
||||
var right = CheckExpression(expression.Right, left.Type);
|
||||
|
||||
Reference in New Issue
Block a user