Skip to content

Commit

Permalink
Fix ternary in thing (#5007)
Browse files Browse the repository at this point in the history
* tests: extend ternary test to cover bugs

See issues #5003, #3690, and #2404

* mparser: store subdir in ternary node

Ternaries don't really need subdirs, but they can be passed into
functions that expect the type they're provided to have a
subdir. Provide it to fulful the interface.

Fixes #5003
Fixes #3690
Fixes #2404
  • Loading branch information
dcbaker authored and jpakkane committed Mar 2, 2019
1 parent cb9b151 commit 841da29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mesonbuild/mparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ def __init__(self, lineno, colno, condition, block):
self.block = block

class TernaryNode(BaseNode):
def __init__(self, lineno, colno, condition, trueblock, falseblock):
def __init__(self, subdir, lineno, colno, condition, trueblock, falseblock):
self.subdir = subdir
self.lineno = lineno
self.colno = colno
self.condition = condition
Expand Down Expand Up @@ -540,7 +541,7 @@ def e1(self):
self.expect('colon')
falseblock = self.e1()
self.in_ternary = False
return TernaryNode(left.lineno, left.colno, left, trueblock, falseblock)
return TernaryNode(left.subdir, left.lineno, left.colno, left, trueblock, falseblock)
return left

def e2(self):
Expand Down
5 changes: 5 additions & 0 deletions test cases/common/113 ternary/meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
project('ternary operator', 'c')

x = true
one = true ? 1 : error('False branch should not be evaluated')
two = false ? error('True branch should not be evaluated.') : 2
three = '@0@'.format(x ? 'yes' : 'no')
four = [x ? '0' : '1']

assert(one == 1, 'Return value from ternary true is wrong.')
assert(two == 2, 'Return value from ternary false is wrong.')
assert(three == 'yes', 'Return value for ternary inside method call is wrong.')
assert(four == ['0'], 'Return value for ternary inside of list is wrong.')

0 comments on commit 841da29

Please sign in to comment.