Skip to content

Commit

Permalink
inference: make getfield_tfunc more robust for abstract PartialStruct (
Browse files Browse the repository at this point in the history
…JuliaLang#34541)

We're currently careful never to make these. But good to be careful?

refs JuliaLang#34513
  • Loading branch information
vtjnash authored and LilithHafner committed Mar 8, 2022
1 parent 280f9d3 commit ba4af1e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ba4af1e

Please sign in to comment.