diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2019-03-02 02:57:24 -0800 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2019-03-02 12:57:24 +0200 |
commit | 841da29d2cc185e7bc96f4d97ec2963472840e9c (patch) | |
tree | 4f306a7b36bb55d145cc49c57f8a49b91073b38a | |
parent | cb9b151985ebc3a8253eb31d1ccb27c0e1d67967 (diff) | |
download | meson-841da29d2cc185e7bc96f4d97ec2963472840e9c.zip meson-841da29d2cc185e7bc96f4d97ec2963472840e9c.tar.gz meson-841da29d2cc185e7bc96f4d97ec2963472840e9c.tar.bz2 |
Fix ternary in thing (#5007)
* 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
-rw-r--r-- | mesonbuild/mparser.py | 5 | ||||
-rw-r--r-- | test cases/common/113 ternary/meson.build | 5 |
2 files changed, 8 insertions, 2 deletions
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py index f18352b..e6a1bce 100644 --- a/mesonbuild/mparser.py +++ b/mesonbuild/mparser.py @@ -405,7 +405,8 @@ class IfNode(BaseNode): 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 @@ -540,7 +541,7 @@ class Parser: 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): diff --git a/test cases/common/113 ternary/meson.build b/test cases/common/113 ternary/meson.build index 3e65046..7539d56 100644 --- a/test cases/common/113 ternary/meson.build +++ b/test cases/common/113 ternary/meson.build @@ -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.') |