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

Member functions of nested structs cannot be called #6917

Closed
AmesingFlank opened this issue Dec 18, 2022 · 5 comments
Closed

Member functions of nested structs cannot be called #6917

AmesingFlank opened this issue Dec 18, 2022 · 5 comments
Assignees

Comments

@AmesingFlank
Copy link
Collaborator

Consider this code segment, where the kernel k calls a member function of c1 which is a member of another struct c2.

@ti.dataclass
class C1:
    i: int

    @ti.func
    def is0(self):
        return self.i == 0

@ti.dataclass
class C2:
    c1: C1

    @ti.func
    def is0(self):
        return self.c1.is0()

@ti.kernel
def k(j:int):
    c1 = C1(j)
    c2 = C2(c1 = c1)
    print(c1.is0())

k(3)

This fails unexpectedly with

Traceback (most recent call last):
  File "/Users/dunfanlu/Code/Taichi/taichi/python/taichi/lang/ast/ast_transformer_utils.py", line 25, in __call__
    return method(ctx, node)
  File "/Users/dunfanlu/Code/Taichi/taichi/python/taichi/lang/ast/ast_transformer.py", line 852, in build_Attribute
    node.ptr = getattr(node.value.ptr, node.attr)
  File "/Users/dunfanlu/Code/Taichi/taichi/python/taichi/lang/common_ops.py", line 26, in __getattr__
    raise AttributeError(
AttributeError: 'Struct15' object has no attribute 'is0'
@oliver-batchelor
Copy link
Contributor

Is this #6652 again?

@AmesingFlank
Copy link
Collaborator Author

Is this #6652 again?

hmm, I don't think it's because I used the same method name. If I use two different names it throws the same error.

@neozhaoliang
Copy link
Contributor

Try the current master branch? I don't have this problem on Ubuntu22.04, intel card.

@AmesingFlank
Copy link
Collaborator Author

Try the current master branch? I don't have this problem on Ubuntu22.04, intel card.

Yep, the latest master works! I'm curious which PR fixed it though haha.

@neozhaoliang
Copy link
Contributor

Should be this one: #6949 :P

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

No branches or pull requests

4 participants