Skip to content

Commit

Permalink
Allow inference of super even if has TypeVars (fix #12636)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Aug 16, 2015
1 parent 6becc96 commit 4e40ad3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ const getfield_tfunc = function (A, s0, name)
end
if isType(s0)
sp = s0.parameters[1]
if isa(sp,DataType) && !any(x->isa(x,TypeVar), sp.parameters)
if isa(sp,DataType)
# TODO
#if fld === :parameters
# return Type{sp.parameters}, true
Expand Down
19 changes: 19 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3211,3 +3211,22 @@ end
# issue #12551 (make sure these don't throw in inference)
Base.return_types(unsafe_load, (Ptr{nothing},))
Base.return_types(getindex, (Vector{nothing},))

# issue #12636
module MyColors

abstract Paint{T}
immutable RGB{T<:FloatingPoint} <: Paint{T}
r::T
g::T
b::T
end

myeltype{T}(::Type{Paint{T}}) = T
myeltype{P<:Paint}(::Type{P}) = myeltype(super(P))
myeltype(::Type{Any}) = Any

end

@test @inferred(MyColors.myeltype(MyColors.RGB{Float32})) == Float32
@test @inferred(MyColors.myeltype(MyColors.RGB)) == Any

0 comments on commit 4e40ad3

Please sign in to comment.