Skip to content

Pointer to structs #608

Open
Open

Description

@certik

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()

Activity

  1. czgdp1807 commented on Jun 17, 2022

    @czgdp1807
    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?

  2. certik commented on Jun 18, 2022

    @certik
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions