Skip to content

Commit 1e32fa1

Browse files
committed
fix some regression of escaped instantiation error during finish_unionall
1 parent 7645f70 commit 1e32fa1

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/jltypes.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,13 @@ static jl_value_t *inst_type_w_(jl_value_t *t, jl_typeenv_t *env, jl_typestack_t
25002500
jl_value_t *b = NULL;
25012501
JL_GC_PUSH2(&a, &b);
25022502
b = inst_type_w_(u->b, env, stack, check, nothrow);
2503+
if (nothrow) {
2504+
// ensure jl_type_union nothrow.
2505+
if (a && !(jl_is_typevar(a) || jl_is_type(a)))
2506+
a = NULL;
2507+
if (b && !(jl_is_typevar(b) || jl_is_type(b)))
2508+
b = NULL;
2509+
}
25032510
if (a != u->a || b != u->b) {
25042511
if (!check) {
25052512
// fast path for `jl_rename_unionall`.
@@ -2531,8 +2538,12 @@ static jl_value_t *inst_type_w_(jl_value_t *t, jl_typeenv_t *env, jl_typestack_t
25312538
else
25322539
t = NULL;
25332540
}
2534-
if (t && v->N) // This branch should never throw.
2535-
N = inst_type_w_(v->N, env, stack, check, 0);
2541+
if (t && v->N) {
2542+
// set nothrow <= 1 to ensure invariant parameter's accuracy.
2543+
N = inst_type_w_(v->N, env, stack, check, nothrow ? 1 : 0);
2544+
if (N == NULL)
2545+
t = NULL;
2546+
}
25362547
}
25372548
if (t && (T != v->T || N != v->N))
25382549
t = (jl_value_t*)jl_wrap_vararg(T, N, check, nothrow);

test/subtype.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,10 +2618,20 @@ end
26182618
abstract type A54356{T<:Real} end
26192619
struct B54356{T} <: A54356{T} end
26202620
struct C54356{S,T<:Union{S,Complex{S}}} end
2621-
let S = Tuple{Val, Val{T}} where {T}, R = Tuple{Val{Val{T}}, Val{T}} where {T}
2622-
# general parameters check
2621+
struct D54356{S<:Real,T} end
2622+
let S = Tuple{Val, Val{T}} where {T}, R = Tuple{Val{Val{T}}, Val{T}} where {T},
2623+
SS = Tuple{Val, Val{T}, Val{T}} where {T}, RR = Tuple{Val{Val{T}}, Val{T}, Val{T}} where {T}
2624+
# parameters check for self
26232625
@testintersect(Tuple{Val{A}, A} where {B, A<:Union{Val{B}, Complex{B}}}, S{1}, R{1})
2626+
# parameters check for supertype (B54356 -> A54356)
26242627
@testintersect(Tuple{Val{A}, A} where {B, A<:Union{Val{B}, B54356{B}}}, S{1}, R{1})
2628+
# enure unused TypeVar skips the `UnionAll` wrapping
2629+
@testintersect(Tuple{Val{A}, A} where {B, A<:(Union{Val{B}, D54356{B,C}} where {C})}, S{1}, R{1})
2630+
# invariant parameter should not get narrowed
2631+
@testintersect(Tuple{Val{A}, A} where {B, A<:Union{Val{B}, Val{Union{Int,Complex{B}}}}}, S{1}, R{1})
2632+
# bit value could not be `Union` element
2633+
@testintersect(Tuple{Val{A}, A, Val{B}} where {B, A<:Union{B, Val{B}}}, SS{1}, RR{1})
2634+
@testintersect(Tuple{Val{A}, A, Val{B}} where {B, A<:Union{B, Complex{B}}}, SS{1}, Union{})
26252635
# `check_datatype_parameters` should ignore bad `Union` elements in constraint's ub
26262636
T = Tuple{Val{Union{Val{Nothing}, Val{C54356{V,V}}}}, Val{Nothing}} where {Nothing<:V<:Nothing}
26272637
@test T <: S{Nothing}
@@ -2630,6 +2640,7 @@ let S = Tuple{Val, Val{T}} where {T}, R = Tuple{Val{Val{T}}, Val{T}} where {T}
26302640
# extra check for Vararg
26312641
@testintersect(Tuple{Val{A}, A} where {B, A<:Union{Val{B}, NTuple{B,Any}}}, S{-1}, R{-1})
26322642
@testintersect(Tuple{Val{A}, A} where {B, A<:Union{Val{B}, Tuple{Any,Vararg{Any,B}}}}, S{-1}, R{-1})
2643+
@testintersect(Tuple{Val{A}, A} where {B, A<:Union{Val{B}, Tuple{Vararg{Int,Union{Int,Complex{B}}}}}}, S{1}, R{1})
26332644
# extra check for NamedTuple
26342645
@testintersect(Tuple{Val{A}, A} where {B, A<:Union{Val{B}, NamedTuple{B,Tuple{Int}}}}, S{1}, R{1})
26352646
@testintersect(Tuple{Val{A}, A} where {B, A<:Union{Val{B}, NamedTuple{B,Tuple{Int}}}}, S{(1,)}, R{(1,)})

0 commit comments

Comments
 (0)