diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py index b3fdba80b..2f0eb2de1 100644 --- a/mesonbuild/mparser.py +++ b/mesonbuild/mparser.py @@ -353,6 +353,7 @@ class Parser: def __init__(self, code): self.stream = Lexer().lex(code) self.getsym() + self.in_ternary = False def getsym(self): try: @@ -393,9 +394,14 @@ class Parser: left.lineno, left.colno) return AssignmentNode(left.lineno, left.colno, left.value, value) elif self.accept('questionmark'): + if self.in_ternary: + raise ParseException('Nested ternary operators are not allowed.', + left.lineno, left.colno) + self.in_ternary = True trueblock = self.e1() self.expect('colon') falseblock = self.e1() + self.in_ternary = False return TernaryNode(left.lineno, left.colno, left, trueblock, falseblock) return left diff --git a/test cases/failing/30 nested ternary/meson.build b/test cases/failing/30 nested ternary/meson.build new file mode 100644 index 000000000..f9c2e5f8a --- /dev/null +++ b/test cases/failing/30 nested ternary/meson.build @@ -0,0 +1,3 @@ +project('nested ternary', 'c') + +x = true ? (false ? 1 : 0) : 2