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.
  • Loading branch information
martinholters authored Sep 1, 2021
1 parent b21d2de commit b5b0684
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 @@ -7586,3 +7586,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 b5b0684

Please sign in to comment.