Skip to content

Commit

Permalink
Replace bool cast by call to bool builtin
Browse files Browse the repository at this point in the history
Some types (e.g. std::tuple) don't support bool cast, let's use the
builtin to do it.
  • Loading branch information
serge-sans-paille committed Oct 17, 2024
1 parent 4c93690 commit 01b97e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pythran/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def visit_IfExp(self, node):
body = self.visit(node.body)
orelse = self.visit(node.orelse)
return (
"(((bool){0}) "
"(pythonic::builtins::functor::bool_{{}}({0}) "
"? typename __combined<decltype({1}), decltype({2})>::type({1}) "
": typename __combined<decltype({1}), decltype({2})>::type({2}))"
).format(test, body, orelse)
Expand Down
5 changes: 5 additions & 0 deletions pythran/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ def test_multidef4(self):
def test_tuple(self):
self.run_test("def tuple_(t): return t[0]+t[1]", (0,1), tuple_=[Tuple[int, int]])

def test_tuple_implicit_empty(self):
self.run_test("def tuple_implicit_empty_(t): return 1 if t else 0",
(0,1),
tuple_implicit_empty_=[Tuple[int, int]])

def test_nested_list_comprehension(self):
self.run_test("def nested_list_comprehension(): return [ [ x+y for x in range(10) ] for y in range(20) ]", nested_list_comprehension=[])

Expand Down

0 comments on commit 01b97e7

Please sign in to comment.