From 3a68be7d9d647a087df439bd38bf46c37d472573 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Mon, 27 Jan 2020 16:22:27 -0500 Subject: [PATCH] inference: make getfield_tfunc more robust for abstract PartialStruct 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 a43c9dd9afff1..ba9bc34660485 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