# TypeVar becomes lost to method implementation?

**URL:** <https://discourse.julialang.org/t/typevar-becomes-lost-to-method-implementation/17364>\
**Category:** General Usage\
**Created:** [November 9, 2018, 8:56pm UTC](https://discourse.julialang.org/t/typevar-becomes-lost-to-method-implementation/17364 "2018-11-09T20:56:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajkeller34](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ajkeller34/32/4416_2.png) [@ajkeller34](https://discourse.julialang.org/u/ajkeller34)\
**Post date:** [November 9, 2018, 8:56pm UTC](https://discourse.julialang.org/t/typevar-becomes-lost-to-method-implementation/17364/1 "2018-11-09T20:56:16Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Post date:** [November 9, 2018, 9:16pm UTC](https://discourse.julialang.org/t/typevar-becomes-lost-to-method-implementation/17364/2 "2018-11-09T21:16:24Z")

</div>

```julia
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
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](https://github.com/JuliaLang/julia/issues/29988).
