Skip to content

Pointer to structs #608

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

Open
certik opened this issue Jun 15, 2022 · 2 comments
Open

Pointer to structs #608

certik opened this issue Jun 15, 2022 · 2 comments

Comments

@certik
Copy link
Contributor

certik commented Jun 15, 2022

After #606 is fixed, we need to support the following use case:

@dataclass
class A:
    x: i32
    y: f32

def f(pa: Pointer[A]):
    print(pa.x)
    print(pa.y)

def g():
    x: A = A()
    px: Pointer[A] = pointer(x)
    px.x = 5
    px.y = 5.5
    f(px)

g()
@czgdp1807
Copy link
Collaborator

Initialisation at declaration is not supported yet. So, instead of the following,

x: A = A()
px: Pointer[A] = pointer(x)

you should use the following,

x: A
x = A()
px: Pointer[A]
px = pointer(x)

Rest everything works. Should we prioritise supporting initialisation at declaration for structs?

@certik
Copy link
Contributor Author

certik commented Jun 18, 2022

I think we can, I opened up #626 for the initialization, I've been hitting bugs in this a lot, and our users will as well, so we might as well sit down and fix it properly and robustly.

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