Skip to content

Commit b0ac45f

Browse files
authored
Merge pull request #48603 from N5N3/temp
Subtype: Avoid split `y::Union` when comparing with a forall var.
2 parents 642216b + 2ab7b6a commit b0ac45f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/subtype.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,9 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param)
12541254
// of unions and vars: if matching `typevar <: union`, first try to match the whole
12551255
// union against the variable before trying to take it apart to see if there are any
12561256
// variables lurking inside.
1257-
ui = pick_union_decision(e, 1);
1257+
// note: for forall var, there's no need to split y if it has no free typevars.
1258+
jl_varbinding_t *xx = lookup(e, (jl_tvar_t *)x);
1259+
ui = ((xx && xx->right) || jl_has_free_typevars(y)) && pick_union_decision(e, 1);
12581260
}
12591261
if (ui == 1)
12601262
y = pick_union_element(y, e, 1);

test/subtype.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,3 +2443,7 @@ end
24432443
let a = (isodd(i) ? Pair{Char, String} : Pair{String, String} for i in 1:2000)
24442444
@test Tuple{Type{Pair{Union{Char, String}, String}}, a...} <: Tuple{Type{Pair{K, V}}, Vararg{Pair{A, B} where B where A}} where V where K
24452445
end
2446+
2447+
#issue 48582
2448+
@test !<:(Tuple{Pair{<:T,<:T}, Val{S} where {S}} where {T<:Base.BitInteger},
2449+
Tuple{Pair{<:T,<:T}, Val{Int}} where {T<:Base.BitInteger})

0 commit comments

Comments
 (0)