@@ -506,7 +506,10 @@ function abstract_call_method(interp::AbstractInterpreter,
506
506
return MethodCallResult (Any, false , false , nothing , Effects ())
507
507
end
508
508
sigtuple = unwrap_unionall (sig)
509
- sigtuple isa DataType || return MethodCallResult (Any, false , false , nothing , Effects ())
509
+ sigtuple isa DataType ||
510
+ return MethodCallResult (Any, false , false , nothing , Effects ())
511
+ all (@nospecialize (x) -> valid_as_lattice (unwrapva (x), true ), sigtuple. parameters) ||
512
+ return MethodCallResult (Union{}, false , false , nothing , EFFECTS_THROWS) # catch bad type intersections early
510
513
511
514
if is_nospecializeinfer (method)
512
515
sig = get_nospecializeinfer_sig (method, sig, sparams)
@@ -1385,25 +1388,35 @@ function precise_container_type(interp::AbstractInterpreter, @nospecialize(itft)
1385
1388
end
1386
1389
if isa (tti, Union)
1387
1390
utis = uniontypes (tti)
1388
- if any (@nospecialize (t) -> ! isa (t, DataType) || ! (t <: Tuple ) || ! isknownlength (t), utis)
1389
- return AbstractIterationResult (Any[Vararg{Any}], nothing , Effects ())
1390
- end
1391
- ltp = length ((utis[1 ]:: DataType ). parameters)
1392
- for t in utis
1393
- if length ((t:: DataType ). parameters) != ltp
1394
- return AbstractIterationResult (Any[Vararg{Any}], nothing )
1391
+ # refine the Union to remove elements that are not valid tags for objects
1392
+ filter! (@nospecialize (x) -> valid_as_lattice (x, true ), utis)
1393
+ if length (utis) == 0
1394
+ return AbstractIterationResult (Any[], nothing ) # oops, this statement was actually unreachable
1395
+ elseif length (utis) == 1
1396
+ tti = utis[1 ]
1397
+ tti0 = rewrap_unionall (tti, tti0)
1398
+ else
1399
+ if any (@nospecialize (t) -> ! isa (t, DataType) || ! (t <: Tuple ) || ! isknownlength (t), utis)
1400
+ return AbstractIterationResult (Any[Vararg{Any}], nothing , Effects ())
1395
1401
end
1396
- end
1397
- result = Any[ Union{} for _ in 1 : ltp ]
1398
- for t in utis
1399
- tps = (t:: DataType ). parameters
1400
- _all (valid_as_lattice, tps) || continue
1401
- for j in 1 : ltp
1402
- result[j] = tmerge (result[j], rewrap_unionall (tps[j], tti0))
1402
+ ltp = length ((utis[1 ]:: DataType ). parameters)
1403
+ for t in utis
1404
+ if length ((t:: DataType ). parameters) != ltp
1405
+ return AbstractIterationResult (Any[Vararg{Any}], nothing )
1406
+ end
1407
+ end
1408
+ result = Any[ Union{} for _ in 1 : ltp ]
1409
+ for t in utis
1410
+ tps = (t:: DataType ). parameters
1411
+ for j in 1 : ltp
1412
+ @assert valid_as_lattice (tps[j], true )
1413
+ result[j] = tmerge (result[j], rewrap_unionall (tps[j], tti0))
1414
+ end
1403
1415
end
1416
+ return AbstractIterationResult (result, nothing )
1404
1417
end
1405
- return AbstractIterationResult (result, nothing )
1406
- elseif tti0 <: Tuple
1418
+ end
1419
+ if tti0 <: Tuple
1407
1420
if isa (tti0, DataType)
1408
1421
return AbstractIterationResult (Any[ p for p in tti0. parameters ], nothing )
1409
1422
elseif ! isa (tti, DataType)
@@ -1667,7 +1680,7 @@ end
1667
1680
return isa_condition (xt, ty, max_union_splitting)
1668
1681
end
1669
1682
@inline function isa_condition (@nospecialize (xt), @nospecialize (ty), max_union_splitting:: Int )
1670
- tty_ub, isexact_tty = instanceof_tfunc (ty)
1683
+ tty_ub, isexact_tty = instanceof_tfunc (ty, true )
1671
1684
tty = widenconst (xt)
1672
1685
if isexact_tty && ! isa (tty_ub, TypeVar)
1673
1686
tty_lb = tty_ub # TODO : this would be wrong if !isexact_tty, but instanceof_tfunc doesn't preserve this info
@@ -1677,7 +1690,7 @@ end
1677
1690
# `typeintersect` may be unable narrow down `Type`-type
1678
1691
thentype = tty_ub
1679
1692
end
1680
- valid_as_lattice (thentype) || (thentype = Bottom)
1693
+ valid_as_lattice (thentype, true ) || (thentype = Bottom)
1681
1694
elsetype = typesubtract (tty, tty_lb, max_union_splitting)
1682
1695
return ConditionalTypes (thentype, elsetype)
1683
1696
end
@@ -1923,7 +1936,7 @@ function abstract_invoke(interp::AbstractInterpreter, (; fargs, argtypes)::ArgIn
1923
1936
ft′ = argtype_by_index (argtypes, 2 )
1924
1937
ft = widenconst (ft′)
1925
1938
ft === Bottom && return CallMeta (Bottom, EFFECTS_THROWS, NoCallInfo ())
1926
- (types, isexact, isconcrete, istype) = instanceof_tfunc (argtype_by_index (argtypes, 3 ))
1939
+ (types, isexact, isconcrete, istype) = instanceof_tfunc (argtype_by_index (argtypes, 3 ), false )
1927
1940
isexact || return CallMeta (Any, Effects (), NoCallInfo ())
1928
1941
unwrapped = unwrap_unionall (types)
1929
1942
if types === Bottom || ! (unwrapped isa DataType) || unwrapped. name != = Tuple. name
@@ -2380,7 +2393,7 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, vtyp
2380
2393
(; rt, effects) = abstract_eval_call (interp, e, vtypes, sv)
2381
2394
t = rt
2382
2395
elseif ehead === :new
2383
- t, isexact = instanceof_tfunc (abstract_eval_value (interp, e. args[1 ], vtypes, sv))
2396
+ t, isexact = instanceof_tfunc (abstract_eval_value (interp, e. args[1 ], vtypes, sv), true )
2384
2397
ut = unwrap_unionall (t)
2385
2398
consistent = ALWAYS_FALSE
2386
2399
nothrow = false
@@ -2444,7 +2457,7 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, vtyp
2444
2457
end
2445
2458
effects = Effects (EFFECTS_TOTAL; consistent, nothrow)
2446
2459
elseif ehead === :splatnew
2447
- t, isexact = instanceof_tfunc (abstract_eval_value (interp, e. args[1 ], vtypes, sv))
2460
+ t, isexact = instanceof_tfunc (abstract_eval_value (interp, e. args[1 ], vtypes, sv), true )
2448
2461
nothrow = false # TODO : More precision
2449
2462
if length (e. args) == 2 && isconcretedispatch (t) && ! ismutabletype (t)
2450
2463
at = abstract_eval_value (interp, e. args[2 ], vtypes, sv)
0 commit comments