"T not defined" when defining parametric one-line function with return type

I noticed the following seemingly weird error when defining an abstract generic type:

abstract type SomeAbstractType{T} end
func(x::SomeAbstractType{T})::Bool where {T} = error("func is not implemented.")

and getting an error like “ERROR: UndefVarError: T not defined”.
However, if the return type is removed then no error occurs:

abstract type SomeAbstractType{T} end
func(x::SomeAbstractType{T}) where {T} = error("func is not implemented.")
# func (generic function with 1 method)

What’s going on here? (I use Julia 1.5)

seems to be a parsing edge case?

julia> function func(x::SomeAbstractType{T})::Bool where {T}
           error("func is not implemented.")
       end
func (generic function with 1 method)

Yes, rewriting the function definition with function keyword seems to eliminate the problem. Is there a bug in the parser, or is it designed to be so?

It’s a known issue: Error in: f(x::T)::Int where T = x · Issue #21847 · JuliaLang/julia · GitHub

3 Likes