Skip to content

Commit 1142759

Browse files
authored
jltypes: ensure revising structs is safe (#51303)
1 parent 5090bc0 commit 1142759

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
@@ -2495,6 +2495,8 @@ void jl_reinstantiate_inner_types(jl_datatype_t *t) // can throw!
24952495

24962496
for (j = 0; j < jl_array_len(partial); j++) {
24972497
jl_datatype_t *ndt = (jl_datatype_t*)jl_array_ptr_ref(partial, j);
2498+
if (ndt == NULL)
2499+
continue;
24982500
assert(jl_unwrap_unionall(ndt->name->wrapper) == (jl_value_t*)t);
24992501
for (i = 0; i < n; i++)
25002502
env[i].val = jl_svecref(ndt->parameters, i);
@@ -2506,6 +2508,8 @@ void jl_reinstantiate_inner_types(jl_datatype_t *t) // can throw!
25062508
if (t->types != jl_emptysvec) {
25072509
for (j = 0; j < jl_array_len(partial); j++) {
25082510
jl_datatype_t *ndt = (jl_datatype_t*)jl_array_ptr_ref(partial, j);
2511+
if (ndt == NULL)
2512+
continue;
25092513
for (i = 0; i < n; i++)
25102514
env[i].val = jl_svecref(ndt->parameters, i);
25112515
assert(ndt->types == NULL);
@@ -2514,7 +2518,9 @@ void jl_reinstantiate_inner_types(jl_datatype_t *t) // can throw!
25142518
if (ndt->isconcretetype) { // cacheable
25152519
jl_compute_field_offsets(ndt);
25162520
}
2521+
jl_array_ptr_set(partial, j, NULL);
25172522
}
2523+
t->name->partial = NULL;
25182524
}
25192525
else {
25202526
assert(jl_field_names(t) == jl_emptysvec);

test/core.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7551,6 +7551,19 @@ end
75517551
struct T36104 # check that redefining it works, issue #21816
75527552
v::Vector{T36104}
75537553
end
7554+
struct S36104{K,V}
7555+
v::S36104{K,V}
7556+
S36104{K,V}() where {K,V} = new()
7557+
S36104{K,V}(x::S36104) where {K,V} = new(x)
7558+
end
7559+
@test !isdefined(Base.unwrap_unionall(Base.ImmutableDict).name, :partial)
7560+
@test !isdefined(S36104.body.body.name, :partial)
7561+
@test hasfield(typeof(S36104.body.body.name), :partial)
7562+
struct S36104{K,V} # check that redefining it works
7563+
v::S36104{K,V}
7564+
S36104{K,V}() where {K,V} = new()
7565+
S36104{K,V}(x::S36104) where {K,V} = new(x)
7566+
end
75547567
# with a gensymmed unionall
75557568
struct Symmetric{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}
75567569
data::S

0 commit comments

Comments
 (0)