unary op bugfix
This commit is contained in:
@@ -296,7 +296,7 @@ public sealed class TypeChecker
|
||||
ArrayIndexAccessSyntax expression => CheckArrayIndexAccess(expression),
|
||||
ArrayInitializerSyntax expression => CheckArrayInitializer(expression),
|
||||
BinaryExpressionSyntax expression => CheckBinaryExpression(expression),
|
||||
UnaryExpressionSyntax expression => CheckUnaryExpression(expression),
|
||||
UnaryExpressionSyntax expression => CheckUnaryExpression(expression, expectedType),
|
||||
DereferenceSyntax expression => CheckDereference(expression),
|
||||
DotFuncCallSyntax expression => CheckDotFuncCall(expression),
|
||||
FuncCallSyntax expression => CheckFuncCall(expression),
|
||||
@@ -525,26 +525,32 @@ public sealed class TypeChecker
|
||||
}
|
||||
}
|
||||
|
||||
private UnaryExpressionNode CheckUnaryExpression(UnaryExpressionSyntax expression)
|
||||
private UnaryExpressionNode CheckUnaryExpression(UnaryExpressionSyntax expression, NubType? expectedType)
|
||||
{
|
||||
switch (expression.Operator)
|
||||
{
|
||||
case UnaryOperatorSyntax.Negate:
|
||||
{
|
||||
var operand = CheckExpression(expression.Operand);
|
||||
if (operand.Type is not NubIntType { Signed: false } and not NubFloatType)
|
||||
var operand = CheckExpression(expression.Operand, expectedType);
|
||||
if (operand.Type is not NubIntType { Signed: true } and not NubFloatType)
|
||||
{
|
||||
throw new TypeCheckerException(Diagnostic.Error("Negation operator must be used with signed integer or float types").At(expression).Build());
|
||||
throw new TypeCheckerException(Diagnostic
|
||||
.Error("Negation operator must be used with signed integer or float types")
|
||||
.At(expression)
|
||||
.Build());
|
||||
}
|
||||
|
||||
return new UnaryExpressionNode(operand.Type, UnaryOperator.Negate, operand);
|
||||
}
|
||||
case UnaryOperatorSyntax.Invert:
|
||||
{
|
||||
var operand = CheckExpression(expression.Operand);
|
||||
var operand = CheckExpression(expression.Operand, expectedType);
|
||||
if (operand.Type is not NubBoolType)
|
||||
{
|
||||
throw new TypeCheckerException(Diagnostic.Error("Invert operator must be used with booleans").At(expression).Build());
|
||||
throw new TypeCheckerException(Diagnostic
|
||||
.Error("Invert operator must be used with booleans")
|
||||
.At(expression)
|
||||
.Build());
|
||||
}
|
||||
|
||||
return new UnaryExpressionNode(operand.Type, UnaryOperator.Invert, operand);
|
||||
|
||||
@@ -28,14 +28,21 @@ extern "main" func main(args: []cstring): i64
|
||||
}
|
||||
raylib::EndDrawing()
|
||||
|
||||
if x + width >= raylib::GetScreenWidth() || x <= 0
|
||||
if x <= 0
|
||||
{
|
||||
direction.x = -direction.x
|
||||
direction.x = 1
|
||||
}
|
||||
|
||||
if y + height >= raylib::GetScreenHeight() || y <= 0
|
||||
else if x + width >= raylib::GetScreenWidth()
|
||||
{
|
||||
direction.y = -direction.y
|
||||
direction.x = -1
|
||||
}
|
||||
else if y <= 0
|
||||
{
|
||||
direction.y = 1
|
||||
}
|
||||
else if y + height >= raylib::GetScreenHeight()
|
||||
{
|
||||
direction.y = -1
|
||||
}
|
||||
|
||||
x = x + @floatToInt(i32, direction.x)
|
||||
|
||||
Reference in New Issue
Block a user