Skip to content

Commit 345c6ec

Browse files
authored
ensure Type{T} gets inserted with the right key when T is a TypeVar (#58577)
Fix #58479
1 parent d0fc242 commit 345c6ec

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/typemap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static jl_value_t *jl_type_extract_name(jl_value_t *t1 JL_PROPAGATES_ROOT, int i
3131
return jl_type_extract_name(jl_unwrap_vararg(t1), invariant);
3232
}
3333
else if (jl_is_typevar(t1)) {
34-
return jl_type_extract_name(((jl_tvar_t*)t1)->ub, invariant);
34+
return jl_type_extract_name(((jl_tvar_t*)t1)->ub, 0);
3535
}
3636
else if (t1 == jl_bottom_type || t1 == (jl_value_t*)jl_typeofbottom_type || t1 == (jl_value_t*)jl_typeofbottom_type->super) {
3737
return (jl_value_t*)jl_typeofbottom_type->name; // put Union{} and typeof(Union{}) and Type{Union{}} together for convenience

test/reflection.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,32 @@ fLargeTable(::Union, ::Union) = "b"
577577
@test length(methods(fLargeTable)) == 205
578578
@test fLargeTable(Union{Int, Missing}, Union{Int, Missing}) == "b"
579579

580+
# issue #58479
581+
fLargeTable(::Type) = "Type"
582+
fLargeTable(::Type{<:DataType}) = "DataType"
583+
@test fLargeTable(Type) == "Type"
584+
@test fLargeTable(DataType) == "DataType"
585+
@test fLargeTable(Type{DataType}) == "DataType"
586+
@test fLargeTable(Type{UnionAll}) == "DataType"
587+
@test fLargeTable(Type{Int}) == "DataType"
588+
@test fLargeTable(Type{Vector}) == "Type"
589+
@test fLargeTable(Type{Type{Union{}}}) == "DataType"
590+
@test fLargeTable(Type{Union{}}) == "Type"
591+
@test fLargeTable(Union{}) == "DataType"
592+
@test fLargeTable(Type{<:DataType}) == "Type"
593+
fLargeTable(::Type{<:UnionAll}) = "UnionAll"
594+
@test fLargeTable(UnionAll) == "UnionAll"
595+
@test fLargeTable(Type{Vector}) == "UnionAll"
596+
@test fLargeTable(Type{Int}) == "DataType"
597+
@test fLargeTable(Type{Type{Union{}}}) == "DataType"
598+
@test fLargeTable(Type{Union{}}) == "Type"
599+
@test_throws MethodError fLargeTable(Union{})
600+
@test fLargeTable(Type{<:DataType}) == "Type"
601+
@test fLargeTable(Type{Vector{T}} where T) == "DataType"
602+
@test fLargeTable(Union{DataType,Type{Vector{T}} where T}) == "DataType"
603+
@test fLargeTable(Union{DataType,UnionAll,Type{Vector{T}} where T}) == "Type"
604+
@test fLargeTable(Union{Type{Vector},Type{Vector{T}} where T}) == "Type"
605+
580606
# issue #15280
581607
function f15280(x) end
582608
@test functionloc(f15280)[2] > 0

0 commit comments

Comments
 (0)