Skip to content

Commit

Permalink
subtype: minor clean up for JuliaLang#55413
Browse files Browse the repository at this point in the history
This commit makes the check more focused on the related error pattern.
  • Loading branch information
N5N3 committed Aug 16, 2024
1 parent 5230d27 commit 1dd8321
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param)
if (jl_is_uniontype(x)) {
if (obviously_egal(x, y))
return 1;
if (e->Runions.depth == 0 && jl_is_typevar(y) && !jl_has_free_typevars(x) && !jl_has_free_typevars(((jl_tvar_t*)y)->ub)) {
if (e->Runions.depth == 0 && jl_is_typevar(y) && !jl_has_free_typevars(x)) {
// Similar to fast path for repeated elements: if there have been no outer
// unions on the right, and the right side is a typevar, then we can handle the
// typevar first before picking a union element, under the theory that it may
Expand All @@ -1325,7 +1325,17 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param)
// free typevars, since the typevars presence might lead to those elements
// getting eliminated (omit_bad_union) or degenerate (Union{Ptr{T}, Ptr}) or
// combined (Union{T, S} where {T, S <: T}).
return subtype_var((jl_tvar_t*)y, x, e, 1, param);
jl_tvar_t *yvar = (jl_tvar_t *)yvar;
jl_varbinding_t *yb = lookup(e, yvar);
while (e->intersection && yb != NULL && yb->lb == yb->ub && jl_is_typevar(yb->lb)) {
yvar = yb->lb;
yb = lookup(e, yvar);
}
// Note: `x <: ∃y` performs a local ∀-∃ check between `x` and `yb->ub`.
// We need to ensure that there's no ∃ typevar as otherwise that check
// might cause false alarm due to the accumulated env change.
if (yb == NULL || yb->right == 0 || !has_exists_typevar(yb->ub, e))
return subtype_var(yvar, x, e, 1, param);
}
x = pick_union_element(x, e, 0);
}
Expand Down

0 comments on commit 1dd8321

Please sign in to comment.