TypeVar becomes lost to method implementation?


#1

I’m trying to understand the following behavior. In short, it seems like in some circumstances a TypeVar can become lost to the method implementation. Is this a bug, or some limitation I’m unaware of with defining methods like Base.show(::IO, ::Type{...})? (using Julia 1.0.1)

julia> struct Test{A,B} end

julia> Base.show(io::IO, ::Type{Test{A,B}}) where {A,B} = print(io, "Test{", A, ",", B, "}")

julia> Test{A,Int} where A
Error showing value of type UnionAll:
ERROR: UndefVarError: A not defined

julia> Base.show(io::IO, ::Type{Test{A,B}}) where {A,B} = print(io, "Test")

julia> Test{A,Int} where A
Test where A

#2
julia> struct Test{A,B} end

julia> fff( ::Type{Test{A,B}}) where {A,B} = print("Test{", A, ",", B, "}")
fff (generic function with 1 method)

julia> fff(Test{A,Int} where A)
ERROR: MethodError: no method matching fff(::Type{Test{A,Int64} where A})
Closest candidates are:
  fff(::Type{Test{A,B}}) where {A, B} at REPL[2]:1
Stacktrace:
 [1] top-level scope at none:0

edit:
Ok, I was wrong. This is weird and looks like a bug. I get

julia> struct Test{A,B} end
julia> Base.show(io::IO, ::Type{Test{A,B}}) where {A,B} = print(io, "fooTest{", A, ",", B, "}")
julia> Test{A,Int} where A
Error showing value of type UnionAll:
ERROR: UndefVarError: A not defined
Stacktrace:
 [1] show(::IOContext{REPL.Terminals.TTYTerminal}, ::Type{SYSTEM: show(lasterr) caused an error
UndefVarError(:A)

Stacktrace:
 [1] show(::IOContext{REPL.Terminals.TTYTerminal}, ::Type{ERROR: UndefVarError: A not defined
Stacktrace:
 [1] show(::IOContext{REPL.Terminals.TTYTerminal}, ::Type{fatal: error thrown and no exception handler available.
UndefVarError(var=:A)
unknown function (ip: 0x7f82971ae438)
...

PS. Opened issue.