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

Confusing error message for param/variable collisions #27710

Closed
jamii opened this issue Jun 21, 2018 · 2 comments
Closed

Confusing error message for param/variable collisions #27710

jamii opened this issue Jun 21, 2018 · 2 comments
Assignees
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage) kind:bug Indicates an unexpected problem or unintended behavior

Comments

@jamii
Copy link
Contributor

jamii commented Jun 21, 2018

Not sure exactly what's going on here, but at the very least the error message is confusing.

julia> struct Foo{T} end

julia> function test()
           types(::Foo{T}) where T = T
           T = types(Foo{Int64}())
       end
test (generic function with 1 method)

julia> test()
ERROR: UndefVarError: T not defined
Stacktrace:
 [1] types at ./REPL[10]:2 [inlined]
 [2] test() at ./REPL[10]:3
 [3] top-level scope

julia> function test2()
           types(::Foo{T}) where T = T
           T2 = types(Foo{Int64}())
       end
test2 (generic function with 1 method)

julia> test2()
Int64
@jamii
Copy link
Contributor Author

jamii commented Jun 21, 2018

I guess the = T is referring to the variable defined later rather than the type param defined previously? I would have expected the type param to shadow the variable.

@martinholters
Copy link
Member

Slightly reduced:

julia> function test()
           T = 1
           foo(::Ref{T}) where T = T
       end
test (generic function with 1 method)

julia> test()(Ref(1))
ERROR: UndefVarError: T not defined

Note than one would probably expect Int to be returned (T bound to the typevar), or possibly 1 (T captured in a closure), but here it seems lowering is confused between the two. And it generates a reference to a yet undefined global:

julia> T = "global"
"global"

julia> test()(Ref(1))
"global"

I don't think that's intended.

@martinholters martinholters added kind:bug Indicates an unexpected problem or unintended behavior compiler:lowering Syntax lowering (compiler front end, 2nd stage) labels Jun 21, 2018
@JeffBezanson JeffBezanson self-assigned this Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage) kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants