@@ -485,7 +485,10 @@ function abstract_call_method(interp::AbstractInterpreter,
485
485
return MethodCallResult (Any, false , false , nothing , Effects ())
486
486
end
487
487
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
489
492
490
493
if is_nospecializeinfer (method)
491
494
sig = get_nospecializeinfer_sig (method, sig, sparams)
@@ -1365,25 +1368,35 @@ function precise_container_type(interp::AbstractInterpreter, @nospecialize(itft)
1365
1368
end
1366
1369
if isa (tti, Union)
1367
1370
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 ())
1375
1381
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
1383
1395
end
1396
+ return AbstractIterationResult (result, nothing )
1384
1397
end
1385
- return AbstractIterationResult (result, nothing )
1386
- elseif tti0 <: Tuple
1398
+ end
1399
+ if tti0 <: Tuple
1387
1400
if isa (tti0, DataType)
1388
1401
return AbstractIterationResult (Any[ p for p in tti0. parameters ], nothing )
1389
1402
elseif ! isa (tti, DataType)
@@ -1647,7 +1660,7 @@ end
1647
1660
return isa_condition (xt, ty, max_union_splitting)
1648
1661
end
1649
1662
@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 )
1651
1664
tty = widenconst (xt)
1652
1665
if isexact_tty && ! isa (tty_ub, TypeVar)
1653
1666
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
1657
1670
# `typeintersect` may be unable narrow down `Type`-type
1658
1671
thentype = tty_ub
1659
1672
end
1660
- valid_as_lattice (thentype) || (thentype = Bottom)
1673
+ valid_as_lattice (thentype, true ) || (thentype = Bottom)
1661
1674
elsetype = typesubtract (tty, tty_lb, max_union_splitting)
1662
1675
return ConditionalTypes (thentype, elsetype)
1663
1676
end
@@ -1903,7 +1916,7 @@ function abstract_invoke(interp::AbstractInterpreter, (; fargs, argtypes)::ArgIn
1903
1916
ft′ = argtype_by_index (argtypes, 2 )
1904
1917
ft = widenconst (ft′)
1905
1918
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 )
1907
1920
isexact || return CallMeta (Any, Effects (), NoCallInfo ())
1908
1921
unwrapped = unwrap_unionall (types)
1909
1922
if types === Bottom || ! (unwrapped isa DataType) || unwrapped. name != = Tuple. name
@@ -2322,7 +2335,7 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, vtyp
2322
2335
(; rt, effects) = abstract_eval_call (interp, e, vtypes, sv)
2323
2336
t = rt
2324
2337
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 )
2326
2339
ut = unwrap_unionall (t)
2327
2340
consistent = noub = ALWAYS_FALSE
2328
2341
nothrow = false
@@ -2387,7 +2400,7 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, vtyp
2387
2400
end
2388
2401
effects = Effects (EFFECTS_TOTAL; consistent, nothrow, noub)
2389
2402
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 )
2391
2404
nothrow = false # TODO : More precision
2392
2405
if length (e. args) == 2 && isconcretedispatch (t) && ! ismutabletype (t)
2393
2406
at = abstract_eval_value (interp, e. args[2 ], vtypes, sv)
0 commit comments