Skip to content

Commit 0eff9d8

Browse files
vtjnashKristofferC
authored andcommitted
jltypes: ensure revising structs is safe (#51303)
(cherry picked from commit 1142759)
1 parent ea93115 commit 0eff9d8

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/jltypes.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,6 +2491,8 @@ void jl_reinstantiate_inner_types(jl_datatype_t *t) // can throw!
24912491

24922492
for (j = 0; j < jl_array_len(partial); j++) {
24932493
jl_datatype_t *ndt = (jl_datatype_t*)jl_array_ptr_ref(partial, j);
2494+
if (ndt == NULL)
2495+
continue;
24942496
assert(jl_unwrap_unionall(ndt->name->wrapper) == (jl_value_t*)t);
24952497
for (i = 0; i < n; i++)
24962498
env[i].val = jl_svecref(ndt->parameters, i);
@@ -2502,6 +2504,8 @@ void jl_reinstantiate_inner_types(jl_datatype_t *t) // can throw!
25022504
if (t->types != jl_emptysvec) {
25032505
for (j = 0; j < jl_array_len(partial); j++) {
25042506
jl_datatype_t *ndt = (jl_datatype_t*)jl_array_ptr_ref(partial, j);
2507+
if (ndt == NULL)
2508+
continue;
25052509
for (i = 0; i < n; i++)
25062510
env[i].val = jl_svecref(ndt->parameters, i);
25072511
assert(ndt->types == NULL);
@@ -2510,7 +2514,9 @@ void jl_reinstantiate_inner_types(jl_datatype_t *t) // can throw!
25102514
if (ndt->isconcretetype) { // cacheable
25112515
jl_compute_field_offsets(ndt);
25122516
}
2517+
jl_array_ptr_set(partial, j, NULL);
25132518
}
2519+
t->name->partial = NULL;
25142520
}
25152521
else {
25162522
assert(jl_field_names(t) == jl_emptysvec);

test/core.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7544,6 +7544,19 @@ end
75447544
struct T36104 # check that redefining it works, issue #21816
75457545
v::Vector{T36104}
75467546
end
7547+
struct S36104{K,V}
7548+
v::S36104{K,V}
7549+
S36104{K,V}() where {K,V} = new()
7550+
S36104{K,V}(x::S36104) where {K,V} = new(x)
7551+
end
7552+
@test !isdefined(Base.unwrap_unionall(Base.ImmutableDict).name, :partial)
7553+
@test !isdefined(S36104.body.body.name, :partial)
7554+
@test hasfield(typeof(S36104.body.body.name), :partial)
7555+
struct S36104{K,V} # check that redefining it works
7556+
v::S36104{K,V}
7557+
S36104{K,V}() where {K,V} = new()
7558+
S36104{K,V}(x::S36104) where {K,V} = new(x)
7559+
end
75477560
# with a gensymmed unionall
75487561
struct Symmetric{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}
75497562
data::S

0 commit comments

Comments
 (0)