# ERROR: UndefVarError: T not defined / Weird Method Parameter Problem

**URL:** <https://discourse.julialang.org/t/error-undefvarerror-t-not-defined-weird-method-parameter-problem/32427>\
**Category:** General Usage\
**Created:** [December 18, 2019, 7:20am UTC](https://discourse.julialang.org/t/error-undefvarerror-t-not-defined-weird-method-parameter-problem/32427 "2019-12-18T07:20:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [December 18, 2019, 7:20am UTC](https://discourse.julialang.org/t/error-undefvarerror-t-not-defined-weird-method-parameter-problem/32427/1 "2019-12-18T07:20:53Z")

</div>

```julia
abstract type Fun{T,R} <: Function end

struct TypedFun{T<:Tuple,R} <: Fun{T,R}
   fn::Function
end

function test(fun::Fun{Tuple{T},Vector{CV} where CV<:T}) where T
      println(T)
end

function testy(fun::Fun{Tuple{T},Vector{CV} where CV<:T}) where T
      :A
end

func = TypedFun{Tuple{Int64},Array{CV,1} where CV<:Int64}(x->[x])

supertype(typeof(func))
Fun{Tuple{Int64},Array{CV,1} where CV<:Int64}

#this works
testy(func)
> :A

#this doesn't work
test(func)

ERROR: UndefVarError: T not defined

```

why? and how can I fix it?

Thanks

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [December 18, 2019, 6:11pm UTC](https://discourse.julialang.org/t/error-undefvarerror-t-not-defined-weird-method-parameter-problem/32427/2 "2019-12-18T18:11:05Z")

</div>

> [@Qiyamah](#):
>
> function test(fun::Fun{Tuple{T},Vector{CV} where CV\<:T}) where T println(T) end

can you provide a constructor for `Fun` ?

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [December 18, 2019, 6:12pm UTC](https://discourse.julialang.org/t/error-undefvarerror-t-not-defined-weird-method-parameter-problem/32427/3 "2019-12-18T18:12:41Z")

</div>

yeah did it in the original post.

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [December 18, 2019, 7:28pm UTC](https://discourse.julialang.org/t/error-undefvarerror-t-not-defined-weird-method-parameter-problem/32427/4 "2019-12-18T19:28:30Z")

</div>

the problem i saw was that: `Array{CV,1} where CV<:Int64}` is not a type. from slack:

```julia
julia> T = Array{A,1} where A<:Int
Array{A,1} where A<:Int64
julia> T.var
A<:Int64
julia> T.var.ub
Int64

```

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [December 18, 2019, 7:33pm UTC](https://discourse.julialang.org/t/error-undefvarerror-t-not-defined-weird-method-parameter-problem/32427/5 "2019-12-18T19:33:30Z")

</div>

> [@longemen3000](#):
>
> `Array{CV,1} where CV<:Int64}` is not a type.

It is a type it is UnionAll . And in the dispatch it should have bounded with Int.  
But it didn’t

---

<div class="post-metadata">

**Author:** ![Syx\_Pek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/syx_pek/32/6364_2.png) [@Syx\_Pek](https://discourse.julialang.org/u/Syx_Pek)\
**Post date:** [December 18, 2019, 7:41pm UTC](https://discourse.julialang.org/t/error-undefvarerror-t-not-defined-weird-method-parameter-problem/32427/6 "2019-12-18T19:41:35Z")

</div>

Here is a MWE showing the problem I think. I’m not sure what cause it but perhaps someone can explain it to me:

```julia
struct F{X} end
f(x::F{Vector{Y} where Y <: X}) where X = println(X)
f(F{Vector{Y} where Y <: Int}()) # errors

```

---

<div class="post-metadata">

**Author:** ![bonStats](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bonstats/32/14277_2.png) [@bonStats](https://discourse.julialang.org/u/bonStats)\
**Post date:** [April 23, 2020, 1:34am UTC](https://discourse.julialang.org/t/error-undefvarerror-t-not-defined-weird-method-parameter-problem/32427/7 "2020-04-23T01:34:50Z")

</div>

Is this error related to:

```julia
struct test{A,B}
    a::A
    b::B
end

f = function(x::test{A,B}) where {A,B}
    test(x.a, x.b)
end 

```

Results in error: UndefVarError: B not defined

```julia
f1 = function(x::test{A,B};) where {A,B}
    test(x.a, x.b)
end 

```

But this has no error

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 23, 2020, 7:46am UTC](https://discourse.julialang.org/t/error-undefvarerror-t-not-defined-weird-method-parameter-problem/32427/8 "2020-04-23T07:46:12Z")

</div>

Welcome to the Julia discourse forum! I am not sure the issue is related to this topic — next time, please open a new discussion.

This looks like a bug, you may want to [open an issue](https://github.com/JuliaLang/julia/issues).

In the meantime, consider the workaround

```julia
f = function(x::test{A,B}) where B where A
    test(x.a, x.b)
end 

```

also note that if you are just trying to define a method for `f`, not a closure,

```julia
function f(x::test{A,B}) where {A,B}
    test(x.a, x.b)
end

```

of course works. Finally, it is common to [capitalize type names](https://docs.julialang.org/en/v1/manual/style-guide/#Use-naming-conventions-consistent-with-Julia-base/-1), eg `Test`.
