From c5c01222437ca24556c3dd2181221b2ce5c7ded9 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 27 Feb 2023 21:47:38 +1100 Subject: [PATCH] BUGFIX: typeof keyword precedence was off --- source/toy_parser.c | 2 +- test/scripts/lib/standard.toy | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/source/toy_parser.c b/source/toy_parser.c index 36b6109..f9a594d 100644 --- a/source/toy_parser.c +++ b/source/toy_parser.c @@ -140,7 +140,7 @@ static Toy_Opcode asType(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { static Toy_Opcode typeOf(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { Toy_ASTNode* rhs = NULL; - parsePrecedence(parser, &rhs, PREC_TERNARY); + parsePrecedence(parser, &rhs, PREC_CALL); Toy_emitASTNodeUnary(nodeHandle, TOY_OP_TYPE_OF, rhs); return TOY_OP_EOF; } diff --git a/test/scripts/lib/standard.toy b/test/scripts/lib/standard.toy index b2e0297..bf7d95e 100644 --- a/test/scripts/lib/standard.toy +++ b/test/scripts/lib/standard.toy @@ -62,6 +62,9 @@ import standard; assert max(a, b, c) == 3, "var.max() failed"; assert max(1, 2, 3, 4, 5, 6, 7, 8, 9, 0) == 9, "max() with many args failed"; + + assert typeof max(1, 2, 3) == int, "typeof max() == int failed"; + assert typeof max(1, 2, 3.4) == float, "typeof max() == float failed"; } @@ -76,6 +79,9 @@ import standard; assert min(a, b, c) == 1, "var.min() failed"; assert min(1, 2, 3, 4, 5, 6, 7, 8, 9, 0) == 0, "min() with many args failed"; + + assert typeof min(1, 2, 3) == int, "typeof min() == int failed"; + assert typeof min(1, 2, 3.4) == float, "typeof min() == float failed"; }