@@ -2723,6 +2723,8 @@ function abstract_eval_isdefined(interp::AbstractInterpreter, e::Expr, vtypes::U
27232723 rt = Const (false ) # never assigned previously
27242724 elseif ! vtyp. undef
27252725 rt = Const (true ) # definitely assigned previously
2726+ else # form `Conditional` to refine `vtyp.undef` in the then branch
2727+ rt = Conditional (sym, vtyp. typ, vtyp. typ, #= isdefined=# true )
27262728 end
27272729 elseif isa (sym, GlobalRef)
27282730 if InferenceParams (interp). assume_bindings_static
@@ -3195,7 +3197,7 @@ end
31953197@inline function abstract_eval_basic_statement (interp:: AbstractInterpreter ,
31963198 @nospecialize (stmt), pc_vartable:: VarTable , frame:: InferenceState )
31973199 if isa (stmt, NewvarNode)
3198- changes = StateUpdate (stmt. slot, VarState (Bottom, true ), false )
3200+ changes = StateUpdate (stmt. slot, VarState (Bottom, true ))
31993201 return BasicStmtChange (changes, nothing , Union{})
32003202 elseif ! isa (stmt, Expr)
32013203 (; rt, exct) = abstract_eval_statement (interp, stmt, pc_vartable, frame)
@@ -3210,7 +3212,7 @@ end
32103212 end
32113213 lhs = stmt. args[1 ]
32123214 if isa (lhs, SlotNumber)
3213- changes = StateUpdate (lhs, VarState (rt, false ), false )
3215+ changes = StateUpdate (lhs, VarState (rt, false ))
32143216 elseif isa (lhs, GlobalRef)
32153217 handle_global_assignment! (interp, frame, lhs, rt)
32163218 elseif ! isa (lhs, SSAValue)
@@ -3220,7 +3222,7 @@ end
32203222 elseif hd === :method
32213223 fname = stmt. args[1 ]
32223224 if isa (fname, SlotNumber)
3223- changes = StateUpdate (fname, VarState (Any, false ), false )
3225+ changes = StateUpdate (fname, VarState (Any, false ))
32243226 end
32253227 return BasicStmtChange (changes, nothing , Union{})
32263228 elseif (hd === :code_coverage_effect || (
@@ -3566,7 +3568,7 @@ function apply_refinement!(𝕃ᵢ::AbstractLattice, slot::SlotNumber, @nospecia
35663568 oldtyp = vtype. typ
35673569 ⊏ = strictpartialorder (𝕃ᵢ)
35683570 if newtyp ⊏ oldtyp
3569- stmtupdate = StateUpdate (slot, VarState (newtyp, vtype. undef), false )
3571+ stmtupdate = StateUpdate (slot, VarState (newtyp, vtype. undef))
35703572 stoverwrite1! (currstate, stmtupdate)
35713573 end
35723574end
@@ -3590,7 +3592,9 @@ function conditional_change(𝕃ᵢ::AbstractLattice, currstate::VarTable, condt
35903592 # "causes" since we ignored those in the comparison
35913593 newtyp = tmerge (𝕃ᵢ, newtyp, LimitedAccuracy (Bottom, oldtyp. causes))
35923594 end
3593- return StateUpdate (SlotNumber (condt. slot), VarState (newtyp, vtype. undef), true )
3595+ # if this `Conditional` is from from `@isdefined condt.slot`, refine its `undef` information
3596+ newundef = condt. isdefined ? ! then_or_else : vtype. undef
3597+ return StateUpdate (SlotNumber (condt. slot), VarState (newtyp, newundef), #= conditional=# true )
35943598end
35953599
35963600function condition_object_change (currstate:: VarTable , condt:: Conditional ,
@@ -3599,7 +3603,7 @@ function condition_object_change(currstate::VarTable, condt::Conditional,
35993603 newcondt = Conditional (condt. slot,
36003604 then_or_else ? condt. thentype : Union{},
36013605 then_or_else ? Union{} : condt. elsetype)
3602- return StateUpdate (condslot, VarState (newcondt, vtype. undef), false )
3606+ return StateUpdate (condslot, VarState (newcondt, vtype. undef))
36033607end
36043608
36053609# make as much progress on `frame` as possible (by handling cycles)
0 commit comments