@@ -489,9 +489,8 @@ function typeof_concrete_vararg(t::DataType)
489489 for i = 1 : np
490490 p = t. parameters[i]
491491 if i == np && isvarargtype (p)
492- pp = unwrap_unionall (p)
493- if isconcretetype (pp. T) && pp. N isa TypeVar
494- return rewrap_unionall (Type{Tuple{t. parameters[1 : np- 1 ]. .. , pp}}, p)
492+ if isdefined (p, :T ) && ! isdefined (p, :N ) && isconcretetype (p. T)
493+ return Type{Tuple{t. parameters[1 : np- 1 ]. .. , Vararg{p. T, N}}} where N
495494 end
496495 elseif ! isconcretetype (p)
497496 break
@@ -555,18 +554,32 @@ function typeassert_type_instance(@nospecialize(v), @nospecialize(t))
555554 widev = widenconst (v)
556555 if widev <: t
557556 return v
558- elseif typeintersect (widev, t) === Bottom
557+ end
558+ ti = typeintersect (widev, t)
559+ if ti === Bottom
559560 return Bottom
560561 end
561562 @assert widev <: Tuple
562563 new_fields = Vector {Any} (undef, length (v. fields))
563564 for i = 1 : length (new_fields)
564- new_fields[i] = typeassert_type_instance (v. fields[i], getfield_tfunc (t, Const (i)))
565- if new_fields[i] === Bottom
566- return Bottom
565+ if isa (v. fields[i], Core. VarargMarker)
566+ new_fields[i] = v. fields[i]
567+ else
568+ new_fields[i] = typeassert_type_instance (v. fields[i], getfield_tfunc (t, Const (i)))
569+ if new_fields[i] === Bottom
570+ return Bottom
571+ end
567572 end
568573 end
569- return tuple_tfunc (new_fields)
574+ tt = tuple_tfunc (new_fields)
575+ if isa (tt, PartialStruct)
576+ if ! (widenconst (tt) <: ti )
577+ return PartialStruct (ti, tt. fields)
578+ end
579+ elseif ! (tt <: ti )
580+ return ti
581+ end
582+ return tt
570583 elseif isa (v, Conditional)
571584 if ! (Bool <: t )
572585 return Bottom
@@ -1133,7 +1146,7 @@ function apply_type_tfunc(@nospecialize(headtypetype), @nospecialize args...)
11331146 return Any
11341147 end
11351148 if ! isempty (args) && isvarargtype (args[end ])
1136- return isvarargtype (headtype) ? Any : Type
1149+ return isvarargtype (headtype) ? Core . VarargMarker : Type
11371150 end
11381151 largs = length (args)
11391152 if headtype === Union
@@ -1175,7 +1188,7 @@ function apply_type_tfunc(@nospecialize(headtypetype), @nospecialize args...)
11751188 end
11761189 return allconst ? Const (ty) : Type{ty}
11771190 end
1178- istuple = (headtype == Tuple)
1191+ istuple = isa (headtype, Type) && (headtype == Tuple)
11791192 if ! istuple && ! isa (headtype, UnionAll) && ! isvarargtype (headtype)
11801193 return Union{}
11811194 end
@@ -1260,11 +1273,11 @@ function apply_type_tfunc(@nospecialize(headtypetype), @nospecialize args...)
12601273 catch ex
12611274 # type instantiation might fail if one of the type parameters
12621275 # doesn't match, which could happen if a type estimate is too coarse
1263- return isvarargtype (headtype) ? Any : Type{<: headtype }
1276+ return isvarargtype (headtype) ? Core . VarargMarker : Type{<: headtype }
12641277 end
12651278 ! uncertain && canconst && return Const (appl)
12661279 if isvarargtype (appl)
1267- return Any
1280+ return Core . VarargMarker
12681281 end
12691282 if istuple
12701283 return Type{<: appl }
@@ -1316,7 +1329,7 @@ function tuple_tfunc(atypes::Vector{Any})
13161329 x = atypes[i]
13171330 # TODO ignore singleton Const (don't forget to update cache logic if you implement this)
13181331 if ! anyinfo
1319- anyinfo = ! isa (x, Type) || isType (x)
1332+ anyinfo = ( ! isa (x, Type) && ! isvarargtype (x) ) || isType (x)
13201333 end
13211334 if isa (x, Const)
13221335 params[i] = typeof (x. val)
0 commit comments