Skip to content

Commit

Permalink
handle unbound vars in NTuple fields (#55405)
Browse files Browse the repository at this point in the history
Comparing objects by `==` will happily answer nonsense for malformed
type comparisons, such as `unwrap_unionall(A) == A`. Avoid forming that
query. Additionally, need to recourse through Vararg when examining type
structure to make decisions.

Fix #55076
Fix #55189
  • Loading branch information
vtjnash authored Aug 8, 2024
1 parent f276757 commit 32423a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,12 @@ static int references_name(jl_value_t *p, jl_typename_t *name, int affects_layou
return references_name(((jl_uniontype_t*)p)->a, name, affects_layout, freevars) ||
references_name(((jl_uniontype_t*)p)->b, name, affects_layout, freevars);
}
if (jl_is_vararg(p)) {
jl_value_t *T = ((jl_vararg_t*)p)->T;
jl_value_t *N = ((jl_vararg_t*)p)->N;
return (T && references_name(T, name, affects_layout, freevars)) ||
(N && references_name(N, name, affects_layout, freevars));
}
if (jl_is_typevar(p))
return 0; // already checked by unionall, if applicable
if (jl_is_datatype(p)) {
Expand Down
6 changes: 3 additions & 3 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,7 @@ static jl_value_t *jl_tupletype_fill(size_t n, jl_value_t *t, int check, int not
t = normalize_unionalls(t);
p = t;
jl_value_t *tw = extract_wrapper(t);
if (tw && t != tw && jl_types_equal(t, tw))
if (tw && t != tw && !jl_has_free_typevars(t) && jl_types_equal(t, tw))
t = tw;
p = t;
check = 0; // remember that checks are already done now
Expand Down Expand Up @@ -2045,7 +2045,7 @@ static jl_value_t *inst_datatype_inner(jl_datatype_t *dt, jl_svec_t *p, jl_value
// normalize types equal to wrappers (prepare for Typeofwrapper)
jl_value_t *tw = extract_wrapper(pi);
if (tw && tw != pi && (tn != jl_type_typename || jl_typeof(pi) == jl_typeof(tw)) &&
jl_types_equal(pi, tw)) {
!jl_has_free_typevars(pi) && jl_types_equal(pi, tw)) {
iparams[i] = tw;
if (p) jl_gc_wb(p, tw);
}
Expand Down Expand Up @@ -2717,7 +2717,7 @@ jl_vararg_t *jl_wrap_vararg(jl_value_t *t, jl_value_t *n, int check, int nothrow
if (valid) {
t = normalize_unionalls(t);
jl_value_t *tw = extract_wrapper(t);
if (tw && t != tw && jl_types_equal(t, tw))
if (tw && t != tw && !jl_has_free_typevars(t) && jl_types_equal(t, tw))
t = tw;
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7495,6 +7495,13 @@ struct A43411{S, T}
end
@test isbitstype(A43411{(:a,), Tuple{Int}})

# issue #55189
struct A55189{N}
children::NTuple{N,A55189{N}}
end
@test fieldtype(A55189{2}, 1) === Tuple{A55189{2}, A55189{2}}
@assert !isbitstype(A55189{2})

# issue #44614
struct T44614_1{T}
m::T
Expand Down

0 comments on commit 32423a8

Please sign in to comment.