Return type annotation with "where"


#1

Not sure if I’m doing this wrong or perhaps this hasn’t been resolved yet: I can annotate the return type or I can have “where” in the function definition but I don’t know how to have both.

struct TypeA
end
something(s::TypeA)::Int = 1 # works
somethingor(s::T) where {T} = 1 # works
somethingorother(s::T)::Int where {T} = 1 #does NOT work

#2

(somethingorother(s::T)::Int) where {T} = 1 # does work

Just add parenthesis


#3

Splendid. Thanks!


#4

See also https://github.com/JuliaLang/julia/issues/21847.