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

[ENH/BUG?] Enum as C array index value: Invalid index type 'Test' #6134

Open
Source61 opened this issue Apr 7, 2024 · 1 comment
Open

[ENH/BUG?] Enum as C array index value: Invalid index type 'Test' #6134

Source61 opened this issue Apr 7, 2024 · 1 comment

Comments

@Source61
Copy link

Source61 commented Apr 7, 2024

Describe the bug

Not sure if this is a bug or enhancement.

I have a C array with defined index ranges in an enum.

In C++ this will compile and run, in Cython this generates the error "Invalid index type 'Test'".

A work-around is to cast the enums to int, but it's ugly and I think unnecessary since enums are already defined as ints?
(Trying to assign 0.4 to Test_Something results in error: enumindex.pyx:3:19: Cannot assign type 'double' to 'int')

Code to reproduce the behaviour:

cdef:
        enum Test:
                Test_Something = 0

        int arr[15]

arr[Test_Something] = 123

Expected behaviour

No response

OS

Linux (Ubuntu 22.04.3 LTS WSL)

Python version

3.10.12

Cython version

3.0.10

Additional context

No response

@da-woods
Copy link
Contributor

da-woods commented Apr 7, 2024

I suspect this should work (for plain enums). It shouldn't for C++ scoped enums though.

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

No branches or pull requests

2 participants