diff --git a/src/compiler.c b/src/compiler.c index 1cd5e79..d76ce26 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -2394,7 +2394,7 @@ static void actualTernary(size_t count, KrkScanner oldScanner, Parser oldParser) emitByte(OP_POP); /* Pop the condition */ consume(TOKEN_ELSE, "Expected 'else' after ternary condition"); - parsePrecedence(PREC_OR); + parsePrecedence(PREC_TERNARY); KrkScanner outScanner = krk_tellScanner(); Parser outParser = parser; diff --git a/test/testNestedTernary.krk b/test/testNestedTernary.krk new file mode 100644 index 0000000..aa4289b --- /dev/null +++ b/test/testNestedTernary.krk @@ -0,0 +1,5 @@ +print('a' if False else 'b' if False else 'c') +print('a' if False else 'b' if True else 'c') +print('a' if True else 'b' if False else 'c') +print('a' if True else 'b' if True else 'c') + diff --git a/test/testNestedTernary.krk.expect b/test/testNestedTernary.krk.expect new file mode 100644 index 0000000..379a139 --- /dev/null +++ b/test/testNestedTernary.krk.expect @@ -0,0 +1,4 @@ +c +b +a +a