From 89d850e4a107c49f62cd868e7b1a72f9bbf00219 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 7 Apr 2022 13:48:04 -0400 Subject: [PATCH] fix missing field type initialization vars (#44797) We were accidentally passing the start of the list instead of the end of the list, resulting in some values passing through uninitialized. Fix #42297 regression (cherry picked from commit 5f2abf6cfaa49220f08900d6a7a4422b94e32187) --- src/jltypes.c | 4 ++-- test/core.jl | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/jltypes.c b/src/jltypes.c index 26288f83edd967..8227c7d629092e 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -1806,7 +1806,7 @@ void jl_reinstantiate_inner_types(jl_datatype_t *t) // can throw! for (i = 0; i < n; i++) env[i].val = jl_svecref(ndt->parameters, i); - ndt->super = (jl_datatype_t*)inst_type_w_((jl_value_t*)t->super, env, &top, 1); + ndt->super = (jl_datatype_t*)inst_type_w_((jl_value_t*)t->super, &env[n - 1], &top, 1); jl_gc_wb(ndt, ndt->super); } @@ -1816,7 +1816,7 @@ void jl_reinstantiate_inner_types(jl_datatype_t *t) // can throw! for (i = 0; i < n; i++) env[i].val = jl_svecref(ndt->parameters, i); assert(ndt->types == NULL); - ndt->types = inst_ftypes(t->types, env, &top); + ndt->types = inst_ftypes(t->types, &env[n - 1], &top); jl_gc_wb(ndt, ndt->types); if (ndt->isconcretetype) { // cacheable jl_compute_field_offsets(ndt); diff --git a/test/core.jl b/test/core.jl index 3424cdbdb418c2..4d5590d7642dc4 100644 --- a/test/core.jl +++ b/test/core.jl @@ -239,6 +239,15 @@ end #struct S22624{A,B,C} <: Ref{S22624{Int64,A}}; end @test_broken @isdefined S22624 +# issue #42297 +mutable struct Node42297{T, V} + value::V + next::Union{Node42297{T, T}, Node42297{T, Val{T}}, Nothing} + Node42297{T}(value) where {T} = new{T, typeof(value)}(value, nothing) +end +@test fieldtype(Node42297{Int,Val{Int}}, 1) === Val{Int} +@test fieldtype(Node42297{Int,Int}, 1) === Int + # issue #3890 mutable struct A3890{T1} x::Matrix{Complex{T1}}