@@ -302,14 +302,34 @@ function type_more_complex(@nospecialize(t), @nospecialize(c), sources::SimpleVe
302302 return true
303303end
304304
305+ # pick a wider type that contains both typea and typeb,
306+ # with some limits on how "large" it can get,
307+ # but without losing too much precision in common cases
308+ # and also trying to be associative and commutative
305309function tmerge (@nospecialize (typea), @nospecialize (typeb))
306310 typea ⊑ typeb && return typeb
307311 typeb ⊑ typea && return typea
312+ # type-lattice for MaybeUndef wrapper
308313 if isa (typea, MaybeUndef) || isa (typeb, MaybeUndef)
309314 return MaybeUndef (tmerge (
310315 isa (typea, MaybeUndef) ? typea. typ : typea,
311316 isa (typeb, MaybeUndef) ? typeb. typ : typeb))
312317 end
318+ # type-lattice for Conditional wrapper
319+ if isa (typea, Conditional) && isa (typeb, Const)
320+ if typeb. val === true
321+ typeb = Conditional (typea. var, Any, Union{})
322+ elseif typeb. val === false
323+ typeb = Conditional (typea. var, Union{}, Any)
324+ end
325+ end
326+ if isa (typeb, Conditional) && isa (typea, Const)
327+ if typea. val === true
328+ typea = Conditional (typeb. var, Any, Union{})
329+ elseif typea. val === false
330+ typea = Conditional (typeb. var, Union{}, Any)
331+ end
332+ end
313333 if isa (typea, Conditional) && isa (typeb, Conditional)
314334 if typea. var === typeb. var
315335 vtype = tmerge (typea. vtype, typeb. vtype)
@@ -320,6 +340,7 @@ function tmerge(@nospecialize(typea), @nospecialize(typeb))
320340 end
321341 return Bool
322342 end
343+ # no special type-inference lattice, join the types
323344 typea, typeb = widenconst (typea), widenconst (typeb)
324345 typea === typeb && return typea
325346 if ! (isa (typea, Type) || isa (typea, TypeVar)) ||
0 commit comments