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

Incorrect type inference when destructing struct into named tuple #3557

Open
rben01 opened this issue Mar 1, 2024 · 0 comments
Open

Incorrect type inference when destructing struct into named tuple #3557

rben01 opened this issue Mar 1, 2024 · 0 comments

Comments

@rben01
Copy link

rben01 commented Mar 1, 2024

Sample code:

struct A
    x::Int
end

struct S
    a::A
end

function f()
    s = S(A(1))
    (; a) = s
    println(a.x)  # !! Missing reference: x
    println(a.a)  # !! This is marked ok, but will fail at runtime
    return nothing
end

Julia allows tuple destructing structs into a named tuple whose fields get assigned to the fields of the struct. However, the Julia extension’s type inference incorrectly infers the type of the resulting variables. In the above example, (; a) = s leads to the extension assuming a has type S, not A. This leads it to think that a doesn't have a field x when it does, and that a does have a field a when it doesn't. Type inference should be updated to correctly unpack the fields of the struct into the named tuple.

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