From 107af38fd185eb6cecd1bf889ccd437cf7a87046 Mon Sep 17 00:00:00 2001 From: George Marques Date: Wed, 15 Sep 2021 11:43:36 -0300 Subject: [PATCH] GDScript: Show error when missing expression after ternary else --- modules/gdscript/gdscript_parser.cpp | 4 ++++ .../parser/errors/missing_expression_after_ternary_else.gd | 4 ++++ .../parser/errors/missing_expression_after_ternary_else.out | 2 ++ 3 files changed, 10 insertions(+) create mode 100644 modules/gdscript/tests/scripts/parser/errors/missing_expression_after_ternary_else.gd create mode 100644 modules/gdscript/tests/scripts/parser/errors/missing_expression_after_ternary_else.out diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 42c06d81615..aafe46b42b1 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -2275,6 +2275,10 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_ternary_operator(Expressio operation->false_expr = parse_precedence(PREC_TERNARY, false); + if (operation->false_expr == nullptr) { + push_error(R"(Expected expression after "else".)"); + } + return operation; } diff --git a/modules/gdscript/tests/scripts/parser/errors/missing_expression_after_ternary_else.gd b/modules/gdscript/tests/scripts/parser/errors/missing_expression_after_ternary_else.gd new file mode 100644 index 00000000000..1f669353291 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/missing_expression_after_ternary_else.gd @@ -0,0 +1,4 @@ +func test(): + var x = 1 if false else + print("oops") + print(x) diff --git a/modules/gdscript/tests/scripts/parser/errors/missing_expression_after_ternary_else.out b/modules/gdscript/tests/scripts/parser/errors/missing_expression_after_ternary_else.out new file mode 100644 index 00000000000..dab6b0a1adb --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/missing_expression_after_ternary_else.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Expected expression after "else".