Return type assertions with type parameters


#1

Today I noticed that

f(x::T)::T where T = x  # throws UndefVarError for T
function f(x::T)::T where T
    x
end  # works

Is this a bug?


Best practice for parametric return type declarations in v0.7 (and v1.0)
New parametric functions syntax has a readability problem
#2

I think it’s just a surprising operator precedence. Your first form is parsed as

julia> :(f(x::T)::T where T)
:(f(x::T)::(T where T))

whereas what you really want is:

julia> (f(x::T)::T) where T = x
f (generic function with 1 method)

julia> f(1)
1

Proper way to declare return types parametrically in short-form functions in Julia 0.6