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

Enums are not correctly resolved when using an alias within a class/struct #214

Open
guitargeek opened this issue Feb 5, 2024 · 2 comments

Comments

@guitargeek
Copy link
Contributor

When defining aliases for an enum, it is not recognized as the right type by cppyy.

Reproducer:

import cppyy

cppyy.cppdef("enum Enum { a,b,c };")
cppyy.cppdef("struct Track { using Type = Enum; };")

# Works!
print(cppyy.gbl.Enum.a)

# Doesn't
print(cppyy.gbl.Track.Type.a)

The output is:

0
Traceback (most recent call last):
  File "/home/rembserj/spaces/master/root/src/root/tst99.py", line 10, in <module>
    print(cppyy.gbl.Track.Type.a)
          ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'int' has no attribute 'a'

In case this is a more complicated problem, any advice on how I can contribute to support this is greatly appreciated!

Originally reported in the ROOT issue tracker:
root-project/root#9246

@wlav
Copy link
Owner

wlav commented Feb 5, 2024

The type Track::Type is actually found as an enum, but it's seen as disjoint from the type Enum, not an alias of it. I'd figure it should resolve as an alias, to make Python's is work. That's a failure of ROOT/meta's type resolution.

However, even if not seen as an alias, the lookup should have worked if a if the enum was properly reflected. Looks like it's not:

import cppyy

cppyy.cppdef("enum Enum { a,b,c };")
cppyy.cppdef("struct Track { using Type = Enum; };")

print("is enum:", cppyy.gbl.gInterpreter.ClassInfo_IsEnum("Track::Type"))

c = cppyy.gbl.CppyyLegacy.TClass.GetClass("Track")
e = c.GetListOfEnums(1).FindObject("Type")
print("is valid:", not not e)

which yields:

is enum: True
is valid: False

In general, ROOT/meta lacks support for using and friend.

@guitargeek
Copy link
Contributor Author

Thank you so much for giving some context @wlav! That helped me to understand where the root cause is, maybe I can fix it at some point.

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

No branches or pull requests

2 participants