Skip to content

Commit

Permalink
Merge pull request #52706 from vnen/gdscript-ternary-operator-crash
Browse files Browse the repository at this point in the history
GDScript: Show error when missing expression after ternary else
  • Loading branch information
akien-mga authored Sep 15, 2021
2 parents ed11d03 + 107af38 commit a4187c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/gdscript/gdscript_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
func test():
var x = 1 if false else
print("oops")
print(x)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected expression after "else".

0 comments on commit a4187c9

Please sign in to comment.