Skip to content

Commit

Permalink
Avoid impossible unionall normalization (#42003)
Browse files Browse the repository at this point in the history
If the unionall bounds are inconsistent with the wrapper's bound, avoid
throwing due to an impossible type instantiation.

(cherry picked from commit b5b0684)
  • Loading branch information
martinholters authored and KristofferC committed Sep 2, 2021
1 parent 38418ad commit 0824c1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1326,8 +1326,15 @@ jl_value_t *normalize_unionalls(jl_value_t *t)
u = (jl_unionall_t*)t;
}

if (u->var->lb == u->var->ub || may_substitute_ub(body, u->var))
t = jl_instantiate_unionall(u, u->var->ub);
if (u->var->lb == u->var->ub || may_substitute_ub(body, u->var)) {
JL_TRY {
t = jl_instantiate_unionall(u, u->var->ub);
}
JL_CATCH {
// just skip normalization
// (may happen for bounds inconsistent with the wrapper's bounds)
}
}
}
JL_GC_POP();
return t;
Expand Down
3 changes: 3 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7584,3 +7584,6 @@ let S = Tuple{Tuple{Tuple{K, UInt128} where K<:Tuple{Int64}, Int64}},
@test pointer_from_objref(T) === pointer_from_objref(S)
@test isbitstype(T)
end

# avoid impossible normalization (don't try to form Tuple{Complex{String}} here)
@test Tuple{Complex{T} where String<:T<:String} == Tuple{Complex{T} where String<:T<:String}

0 comments on commit 0824c1b

Please sign in to comment.