From 0824c1bca3f7b1e770178086f4991896cfcc291b Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Wed, 1 Sep 2021 19:43:37 +0200 Subject: [PATCH] Avoid impossible unionall normalization (#42003) If the unionall bounds are inconsistent with the wrapper's bound, avoid throwing due to an impossible type instantiation. (cherry picked from commit b5b0684ec0a66c1bd50e75c25c724c20526bb702) --- src/jltypes.c | 11 +++++++++-- test/core.jl | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/jltypes.c b/src/jltypes.c index c4f5a1aff88bd..43171ee332e87 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -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; diff --git a/test/core.jl b/test/core.jl index 56ddfb42e10f1..74edc7cddf7f4 100644 --- a/test/core.jl +++ b/test/core.jl @@ -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}