From ba4af1e668e1ad54ca5069a830f3e698228bb7ae Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Tue, 31 Aug 2021 13:15:04 -0400 Subject: [PATCH] inference: make getfield_tfunc more robust for abstract PartialStruct (#34541) We're currently careful never to make these. But good to be careful? refs #34513 --- base/compiler/tfuncs.jl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/base/compiler/tfuncs.jl b/base/compiler/tfuncs.jl index a43c9dd9afff10..ba9bc34660485c 100644 --- a/base/compiler/tfuncs.jl +++ b/base/compiler/tfuncs.jl @@ -826,17 +826,18 @@ function getfield_tfunc(@nospecialize(s00), @nospecialize(name)) end end s = typeof(sv) - elseif isa(s, PartialStruct) + elseif isa(s00, PartialStruct) + s = widenconst(s00) + sty = unwrap_unionall(s)::DataType if isa(name, Const) nv = name.val if isa(nv, Symbol) - nv = fieldindex(widenconst(s), nv, false) + nv = fieldindex(sty, nv, false) end - if isa(nv, Int) && 1 <= nv <= length(s.fields) - return unwrapva(s.fields[nv]) + if isa(nv, Int) && 1 <= nv <= length(s00.fields) + return unwrapva(s00.fields[nv]) end end - s = widenconst(s) end if isType(s) || !isa(s, DataType) || isabstracttype(s) return Any