Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible types in conditional expression #3446

Open
isuruf opened this issue Mar 18, 2020 · 1 comment
Open

Incompatible types in conditional expression #3446

isuruf opened this issue Mar 18, 2020 · 1 comment

Comments

@isuruf
Copy link
Contributor

@isuruf isuruf commented Mar 18, 2020

For the following simple program,

a = 1
b = (True, False) if a > 0 else (False,)

It's accepted by python, but not cython

(/home/isuru/miniforge3) isuru@isuru:~$ cython --version
Cython version 0.29.15
(/home/isuru/miniforge3) isuru@isuru:~$ cat cython_test.py 
a = 1
b = (True, False) if a > 0 else (False,)
(/home/isuru/miniforge3) isuru@isuru:~$ python cython_test.py 
(/home/isuru/miniforge3) isuru@isuru:~$ cython cython_test.py 
/home/isuru/miniforge3/lib/python3.7/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/isuru/cython_test.py
  tree = Parsing.p_module(s, pxd, full_module_name)

Error compiling Cython file:
------------------------------------------------------------
...
a = 1
b = (True, False) if a > 0 else (False,)
   ^
------------------------------------------------------------

cython_test.py:2:4: Incompatible types in conditional expression ((bint, bint); (bint))
@scoder

This comment has been minimized.

Copy link
Contributor

@scoder scoder commented Mar 19, 2020

Thanks for the report. We should coerce both to Python objects (i.e. tuples) in this case, if the resulting ctuple types are not compatible.

PR welcome, see CondExprNode in ExprNodes.py. Tests can go into tests/run/if_else_expr.pyx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.