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

Wrong inferred types for variables declarated by property destructuring #357

Open
HugoMelchers opened this issue Nov 9, 2022 · 0 comments

Comments

@HugoMelchers
Copy link

When declaring a variable by property destructuring, type inference incorrectly infers that the new variable has the same type as the right hand side, instead of the corresponding field of the right hand side. This results in false positive warnings about the usage of the variable, for example julia-vscode #2639. For example, in the following tests the first test fails, while the second test passes:

@testset "type-inference in property destructuring" begin
    cst = parse_and_pass("""
    struct S
        a
    end

    struct T
        s::S
    end

    function f1(t::T)
        (; s) = t
        a = s.a
    end

    function f2(t::T)
        s = t.s
        x = s.a
    end
    """)
    
    S = cst.meta.scope.names["S"]
    @test cst.meta.scope.names["f1"].val.meta.scope.names["s"].type == S # fails, left-hand side is type T instead of S
    @test cst.meta.scope.names["f2"].val.meta.scope.names["s"].type == S # passes
end
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

1 participant