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}}