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 staticfloat committed Dec 22, 2022
1 parent 97e5a68 commit 6db81b9
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 @@ -1200,8 +1200,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 @@ -7549,3 +7549,6 @@ const T35130 = Tuple{Vector{Int}, <:Any}
end
h35130(x) = A35130(Any[x][1]::Vector{T35130})
@test h35130(T35130[([1],1)]) isa A35130

# 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 6db81b9

Please sign in to comment.