Erroneous automatic promotion

question
bug

#1

While composing a minimal working example for #11821, I came across the following:

struct foo{T} <: T where {T<:Real}
    bar::T
end

seems to not throw a convert MethodError for declarations such as

julia> foo(3.0 + 1im)
foo{Complex{Float64}}(3.0 + 1.0im)

This is naturally absent when there’s no subtyping:

struct foo{T<:Real}
    bar::T
end

will prompt a convert MethodError for foo(3.0 + 1im).


#2

The Ts in the first example are not the same, I think your example is equivalent with

struct foo{S} <: T where {T<:Real}
    bar::S
end

since those T have different scope.