# ERROR: LoadError: UndefVarError: A not defined

**URL:** <https://discourse.julialang.org/t/error-loaderror-undefvarerror-a-not-defined/38116>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 24, 2020, 12:31am UTC](https://discourse.julialang.org/t/error-loaderror-undefvarerror-a-not-defined/38116 "2020-04-24T00:31:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![logankilpatrick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/logankilpatrick/32/38123_2.png) [@logankilpatrick](https://discourse.julialang.org/u/logankilpatrick)\
**Post date:** [April 24, 2020, 12:31am UTC](https://discourse.julialang.org/t/error-loaderror-undefvarerror-a-not-defined/38116/1 "2020-04-24T00:31:37Z")

</div>

Hey all, I have the following code:

```julia
function POMDPs.action(pol::MyCustomType,s::S)::A where {S,A}
   # ignore
end

```

This code works on Julia 1.1.1 but errors on Julia 1.3 + and says “ERROR: LoadError: UndefVarError: A not defined”. Is this a syntax change I missed in one of the new Julia versions (I looked and could not find this syntax mentioned in the release notes anywhere) ?

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [April 24, 2020, 1:50am UTC](https://discourse.julialang.org/t/error-loaderror-undefvarerror-a-not-defined/38116/2 "2020-04-24T01:50:04Z")

</div>

Simpler reproducible example:

```julia
julia> VERSION
v"1.1.0"

julia> foo(x::T)::T where {T} = x
ERROR: UndefVarError: T not defined
Stacktrace:
 [1] top-level scope at none:0

```

Are you sure this works on Julia 1.1.1? Maybe you just defined `A` somewhere?

```julia
julia> const T = Float32
Float32

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

julia> foo(2.3)
ERROR: MethodError: no method matching foo(::Float64)
Closest candidates are:
  foo(::Float32) at REPL[7]:1
Stacktrace:
 [1] top-level scope at none:0

julia> foo(2.3f0)
2.3f0

```

---

<div class="post-metadata">

**Author:** ![logankilpatrick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/logankilpatrick/32/38123_2.png) [@logankilpatrick](https://discourse.julialang.org/u/logankilpatrick)\
**Post date:** [April 24, 2020, 1:18pm UTC](https://discourse.julialang.org/t/error-loaderror-undefvarerror-a-not-defined/38116/3 "2020-04-24T13:18:39Z")

</div>

Yeah, it works on 1.1.1.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [April 24, 2020, 1:50pm UTC](https://discourse.julialang.org/t/error-loaderror-undefvarerror-a-not-defined/38116/4 "2020-04-24T13:50:11Z")

</div>

But it doesn’t work on 1.1.0, as I showed above.  
EDIT, doesn’t work on 1.1.2-pre either:

```julia
julia> VERSION
v"1.1.2-pre.0"

julia> foo(x::T)::T where {T} = x
ERROR: UndefVarError: T not defined
Stacktrace:
 [1] top-level scope at none:0

```

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [April 25, 2020, 4:02am UTC](https://discourse.julialang.org/t/error-loaderror-undefvarerror-a-not-defined/38116/5 "2020-04-25T04:02:17Z")

</div>

There are some pretty weird behaviors here, at least in julia 1.2 and 1.4, that maybe shouldn’t be allowed syntactically at all. Basically, what I’m saying below is that the OP should continue to be an error, because A is indeed not defined, but also that other things shouldn’t be allowed either…

The following doesn’t really make sense if `T` isn’t defined at parse time. So it should error at that stage, rather than when called.

```julia
julia> foo(x)::T = x # should error here, T not defined

julia> foo(1)
ERROR: UndefVarError: T not defined

```

Even crazier, if you define `T` _after_ defining the function but before calling it, it will work, and then changing `T` later will change the behavior of the function!

```julia
julia> foo(x)::T = x
foo (generic function with 1 method)

julia> T = Float32
Float32

julia> foo(1)
1.0f0

julia> T = Float64
Float64

julia> foo(1) # holy cow!
1.0

```

I’m not sure if there’s any value to having this be possible, and maybe it’s important in some way I don’t realize, but if not it seems like it should be a parse time error to use types in a definition that aren’t associated with the arguments (in a `where` context) or previously defined.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [April 25, 2020, 9:21am UTC](https://discourse.julialang.org/t/error-loaderror-undefvarerror-a-not-defined/38116/6 "2020-04-25T09:21:51Z")

</div>

These are just closure which capture the variable binding (and not the value at the time of the closure creation). Here a recent tidbit from Jeff, musing whether value-capture would have been better:

[![](https://global.discourse-cdn.com/julialang/original/3X/8/f/8f4c9c52aec99b2306fc6bfcddc768cd8423b1c7.jpeg "Ask us anything: Jeff Bezanson and Stefan Karpinski") ](https://www.youtube.com/watch?v=vfxS6_Sx1Pk&t=3031)

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [April 25, 2020, 9:03pm UTC](https://discourse.julialang.org/t/error-loaderror-undefvarerror-a-not-defined/38116/7 "2020-04-25T21:03:15Z")

</div>

Interesting. Thanks for that!
