diff --git a/src/celpy/evaluation.py b/src/celpy/evaluation.py index 47caf9b..a955ca6 100644 --- a/src/celpy/evaluation.py +++ b/src/celpy/evaluation.py @@ -1322,10 +1322,12 @@ def expr(self, tree: lark.Tree) -> Result: elif len(tree.children) == 3: # full conditionalor "?" conditionalor ":" expr. func = self.functions["_?_:_"] - cond_value, left, right = cast(Tuple[Result, Result, Result], self.visit_children(tree)) + cond_value = self.visit(tree.children[0]) try: - return func(cond_value, left, right) + return self.visit(tree.children[1]) if func(cond_value, True, False) else self.visit(tree.children[2]) except TypeError as ex: + left = self.visit(tree.children[1]) if cond_value else '-' + right = self.visit(tree.children[2]) if cond_value else '-' self.logger.debug("%s(%s, %s) --> %s", func.__name__, left, right, ex) err = ( f"found no matching overload for _?_:_ " @@ -1341,6 +1343,9 @@ def expr(self, tree: lark.Tree) -> Result: column=tree.meta.column, ) + def visit(self, child: Union[str, lark.Tree]): + return super().visit(child) if isinstance(child, lark.Tree) else child + @trace def conditionalor(self, tree: lark.Tree) -> Result: """ diff --git a/type_check/lineprecision.txt b/type_check/lineprecision.txt index b80b663..236743a 100644 --- a/type_check/lineprecision.txt +++ b/type_check/lineprecision.txt @@ -9,3 +9,4 @@ celpy.celtypes 1495 430 17 221 788 39 celpy.evaluation 2434 824 33 172 1390 15 xlate 0 0 0 0 0 0 xlate.c7n_to_cel 1730 384 105 145 1091 5 +