Closed
Description
MRE:
# should invalidate old constraint wrapped in PartialStruct when the subject of condition has changed
let M = Module()
@eval M begin
struct BePartialStruct
val::Int
cond
end
end
rt = @eval M begin
Base.return_types((Union{Nothing,Int},)) do a
cond = a === nothing
obj = $(Expr(:new, M.BePartialStruct, 42, :cond))
r1 = getfield(obj, :cond) ? 0 : a # r1::Int
a = $(gensym(:anyvar))::Any
r2 = getfield(obj, :cond) ? a : nothing # r2::Any, not r2::Const(nothing)
return r1, r2 # ::Tuple{Int,Any}
end |> only
end
@test rt == Tuple{Int,Any}
end
I encountered Conditional
wrapped in PartialStruct
when the Conditional
is captured in a closure.
Solutions:
- (dirty, but more accurate) we can add another special case as like
LimitedAccuracy
:julia/base/compiler/typelattice.jl
Line 366 in 3aada59
- (simple, but less accurate) disallow
PartialStruct
to wrapConditional
Which one do we want ?