diff --git a/src/datatype.c b/src/datatype.c index 9cf1ec58e09e9..fd0d8639aae48 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -311,6 +311,18 @@ void jl_compute_field_offsets(jl_datatype_t *st) // based on whether its definition is self-referential if (w->types != NULL) { st->isbitstype = st->isinlinealloc = st->isconcretetype && !st->mutabl; + if (st->isinlinealloc) { + size_t i, nf = jl_svec_len(w->types); + for (i = 0; i < nf; i++) { + jl_value_t *fld = jl_svecref(w->types, i); + if (references_name(fld, w->name)) { + st->isinlinealloc = 0; + st->isbitstype = 0; + st->zeroinit = 1; + break; + } + } + } size_t i, nf = jl_svec_len(st->types); for (i = 0; i < nf; i++) { jl_value_t *fld = jl_svecref(st->types, i); @@ -327,18 +339,6 @@ void jl_compute_field_offsets(jl_datatype_t *st) st->has_concrete_subtype &= !jl_is_datatype(fld) || ((jl_datatype_t *)fld)->has_concrete_subtype; } } - if (st->isinlinealloc) { - size_t i, nf = jl_svec_len(w->types); - for (i = 0; i < nf; i++) { - jl_value_t *fld = jl_svecref(w->types, i); - if (references_name(fld, w->name)) { - st->isinlinealloc = 0; - st->isbitstype = 0; - st->zeroinit = 1; - break; - } - } - } } // If layout doesn't depend on type parameters, it's stored in st->name->wrapper // and reused by all subtypes. diff --git a/test/core.jl b/test/core.jl index bf0d8c9d45d5f..cefb450ff3853 100644 --- a/test/core.jl +++ b/test/core.jl @@ -5924,6 +5924,14 @@ let x = UnionFieldInlineStruct(1, 3.14) @test CInlineUnion[end] == x end +# issue 33709 +struct A33709 + a::Union{Nothing,A33709} +end +let a33709 = A33709(A33709(nothing)) + @test isnothing(a33709.a.a) +end + # issue 31583 a31583 = "a" f31583() = a31583 === "a"