# Parser bug regarding parametric function expressions?

**URL:** <https://discourse.julialang.org/t/parser-bug-regarding-parametric-function-expressions/81848>\
**Category:** Internals & Design\
**Tags:** potential-bug\
**Created:** [May 28, 2022, 10:31pm UTC](https://discourse.julialang.org/t/parser-bug-regarding-parametric-function-expressions/81848 "2022-05-28T22:31:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [May 28, 2022, 10:31pm UTC](https://discourse.julialang.org/t/parser-bug-regarding-parametric-function-expressions/81848/1 "2022-05-28T22:31:43Z")

</div>

Some weird behavior here.

Suppose we have this:

```julia
SomeType = Tuple{Int8, Int16}
f(::Type{Tuple{A, B}}) where {A <: Any, B <: Any} = B

```

If we now do `f(SomeType)`, we get `Int16` in return as expected.

The following however, results in `ERROR: UndefVarError: B not defined` on both 1.7.3 and on 1.8.0-beta3:

```julia
(function(::Type{Tuple{A, B}}) where {A <: Any, B <: Any}
   B
 end)(SomeType)

```

EDIT: Github issue: [UndefVarError when trying to use parametric function expression · Issue #45506 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/45506)

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 29, 2022, 9:03pm UTC](https://discourse.julialang.org/t/parser-bug-regarding-parametric-function-expressions/81848/2 "2022-05-29T21:03:27Z")

</div>

Try this:

```julia
julia> SomeType = Tuple{Int8, Int16}
Tuple{Int8, Int16}

julia> (function (::Type{Tuple{A, B}}) where A where B
          B
        end)(SomeType)
Int16

```

or this:

```julia
julia> (function (::Type{Tuple{A, B}} where A) where B
          B
        end)(SomeType)
Int16

```

It possibly a bug, since adding an function identifier also makes this work, but I’m also suspecting a potential operator precedence issue.

```julia
julia> (function f(::Type{Tuple{A, B}}) where {A,B}
          B
        end)(SomeType)
Int16

```

This does look suspciously like a bug though.

```julia
julia> :(function(::Type{Tuple{A, B}}) where {A, B}
          B
        end)
:(function (::Type{Tuple{A, B}},) where A
      #= REPL[24]:1 =#
      #= REPL[24]:2 =#
      B
  end)

```

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [December 9, 2022, 6:07pm UTC](https://discourse.julialang.org/t/parser-bug-regarding-parametric-function-expressions/81848/3 "2022-12-09T18:07:57Z")

</div>

Reportedly this issue is fixed now.

The bugfix is tiny too: it just adds two characters in a single line:

> <https://github.com/JuliaLang/julia/commit/9c563ad6a4b5568e07d88776c42dd5c47fabc45b#diff-dab3bf143caa5fd13741273c8f552236315cd2964e1f1a0139e147b20d2d8e52L1355>
>
> Was throwing away the tail of the list, dropping the result of where clauses.
> 
> …
> Fixes #45506
