@@ -485,7 +485,10 @@ function abstract_call_method(interp::AbstractInterpreter,
485485 return MethodCallResult (Any, false , false , nothing , Effects ())
486486 end
487487 sigtuple = unwrap_unionall (sig)
488- sigtuple isa DataType || return MethodCallResult (Any, false , false , nothing , Effects ())
488+ sigtuple isa DataType ||
489+ return MethodCallResult (Any, false , false , nothing , Effects ())
490+ all (@nospecialize (x) -> valid_as_lattice (unwrapva (x), true ), sigtuple. parameters) ||
491+ return MethodCallResult (Union{}, false , false , nothing , EFFECTS_THROWS) # catch bad type intersections early
489492
490493 if is_nospecializeinfer (method)
491494 sig = get_nospecializeinfer_sig (method, sig, sparams)
@@ -1365,25 +1368,35 @@ function precise_container_type(interp::AbstractInterpreter, @nospecialize(itft)
13651368 end
13661369 if isa (tti, Union)
13671370 utis = uniontypes (tti)
1368- if any (@nospecialize (t) -> ! isa (t, DataType) || ! (t <: Tuple ) || ! isknownlength (t), utis)
1369- return AbstractIterationResult (Any[Vararg{Any}], nothing , Effects ())
1370- end
1371- ltp = length ((utis[1 ]:: DataType ). parameters)
1372- for t in utis
1373- if length ((t:: DataType ). parameters) != ltp
1374- return AbstractIterationResult (Any[Vararg{Any}], nothing )
1371+ # refine the Union to remove elements that are not valid tags for objects
1372+ filter! (@nospecialize (x) -> valid_as_lattice (x, true ), utis)
1373+ if length (utis) == 0
1374+ return AbstractIterationResult (Any[], nothing ) # oops, this statement was actually unreachable
1375+ elseif length (utis) == 1
1376+ tti = utis[1 ]
1377+ tti0 = rewrap_unionall (tti, tti0)
1378+ else
1379+ if any (@nospecialize (t) -> ! isa (t, DataType) || ! (t <: Tuple ) || ! isknownlength (t), utis)
1380+ return AbstractIterationResult (Any[Vararg{Any}], nothing , Effects ())
13751381 end
1376- end
1377- result = Any[ Union{} for _ in 1 : ltp ]
1378- for t in utis
1379- tps = (t:: DataType ). parameters
1380- _all (valid_as_lattice, tps) || continue
1381- for j in 1 : ltp
1382- result[j] = tmerge (result[j], rewrap_unionall (tps[j], tti0))
1382+ ltp = length ((utis[1 ]:: DataType ). parameters)
1383+ for t in utis
1384+ if length ((t:: DataType ). parameters) != ltp
1385+ return AbstractIterationResult (Any[Vararg{Any}], nothing )
1386+ end
1387+ end
1388+ result = Any[ Union{} for _ in 1 : ltp ]
1389+ for t in utis
1390+ tps = (t:: DataType ). parameters
1391+ for j in 1 : ltp
1392+ @assert valid_as_lattice (tps[j], true )
1393+ result[j] = tmerge (result[j], rewrap_unionall (tps[j], tti0))
1394+ end
13831395 end
1396+ return AbstractIterationResult (result, nothing )
13841397 end
1385- return AbstractIterationResult (result, nothing )
1386- elseif tti0 <: Tuple
1398+ end
1399+ if tti0 <: Tuple
13871400 if isa (tti0, DataType)
13881401 return AbstractIterationResult (Any[ p for p in tti0. parameters ], nothing )
13891402 elseif ! isa (tti, DataType)
@@ -1647,7 +1660,7 @@ end
16471660 return isa_condition (xt, ty, max_union_splitting)
16481661end
16491662@inline function isa_condition (@nospecialize (xt), @nospecialize (ty), max_union_splitting:: Int )
1650- tty_ub, isexact_tty = instanceof_tfunc (ty)
1663+ tty_ub, isexact_tty = instanceof_tfunc (ty, true )
16511664 tty = widenconst (xt)
16521665 if isexact_tty && ! isa (tty_ub, TypeVar)
16531666 tty_lb = tty_ub # TODO : this would be wrong if !isexact_tty, but instanceof_tfunc doesn't preserve this info
@@ -1657,7 +1670,7 @@ end
16571670 # `typeintersect` may be unable narrow down `Type`-type
16581671 thentype = tty_ub
16591672 end
1660- valid_as_lattice (thentype) || (thentype = Bottom)
1673+ valid_as_lattice (thentype, true ) || (thentype = Bottom)
16611674 elsetype = typesubtract (tty, tty_lb, max_union_splitting)
16621675 return ConditionalTypes (thentype, elsetype)
16631676 end
@@ -1903,7 +1916,7 @@ function abstract_invoke(interp::AbstractInterpreter, (; fargs, argtypes)::ArgIn
19031916 ft′ = argtype_by_index (argtypes, 2 )
19041917 ft = widenconst (ft′)
19051918 ft === Bottom && return CallMeta (Bottom, EFFECTS_THROWS, NoCallInfo ())
1906- (types, isexact, isconcrete, istype) = instanceof_tfunc (argtype_by_index (argtypes, 3 ))
1919+ (types, isexact, isconcrete, istype) = instanceof_tfunc (argtype_by_index (argtypes, 3 ), false )
19071920 isexact || return CallMeta (Any, Effects (), NoCallInfo ())
19081921 unwrapped = unwrap_unionall (types)
19091922 if types === Bottom || ! (unwrapped isa DataType) || unwrapped. name != = Tuple. name
@@ -2322,7 +2335,7 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, vtyp
23222335 (; rt, effects) = abstract_eval_call (interp, e, vtypes, sv)
23232336 t = rt
23242337 elseif ehead === :new
2325- t, isexact = instanceof_tfunc (abstract_eval_value (interp, e. args[1 ], vtypes, sv))
2338+ t, isexact = instanceof_tfunc (abstract_eval_value (interp, e. args[1 ], vtypes, sv), true )
23262339 ut = unwrap_unionall (t)
23272340 consistent = noub = ALWAYS_FALSE
23282341 nothrow = false
@@ -2387,7 +2400,7 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, vtyp
23872400 end
23882401 effects = Effects (EFFECTS_TOTAL; consistent, nothrow, noub)
23892402 elseif ehead === :splatnew
2390- t, isexact = instanceof_tfunc (abstract_eval_value (interp, e. args[1 ], vtypes, sv))
2403+ t, isexact = instanceof_tfunc (abstract_eval_value (interp, e. args[1 ], vtypes, sv), true )
23912404 nothrow = false # TODO : More precision
23922405 if length (e. args) == 2 && isconcretedispatch (t) && ! ismutabletype (t)
23932406 at = abstract_eval_value (interp, e. args[2 ], vtypes, sv)
0 commit comments