Skip to content

Commit 5a612a3

Browse files
committed
Simplify appliedTo
Only use one method instead of a succession of two.
1 parent d69d1b7 commit 5a612a3

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -483,25 +483,7 @@ class TypeApplications(val self: Type) extends AnyVal {
483483
* 3. If `T` is a polytype, instantiate it to `U1,...,Un`.
484484
*/
485485
final def appliedTo(args: List[Type])(implicit ctx: Context): Type = /*>|>*/ track("appliedTo") /*<|<*/ {
486-
if (args.isEmpty || ctx.erasedTypes) self
487-
else self.stripTypeVar match { // TODO investigate why we can't do safeDealias here
488-
case self: GenericType if !args.exists(_.isInstanceOf[TypeBounds]) =>
489-
self.instantiate(args)
490-
case EtaExpansion(self1) =>
491-
self1.appliedTo(args)
492-
case self1: WildcardType =>
493-
self1
494-
case _ =>
495-
self.appliedTo(args, typeParams)
496-
}
497-
}
498-
499-
/** Encode application `T[U1, ..., Un]` without simplifications, where
500-
* @param self = `T`
501-
* @param args = `U1, ..., Un`
502-
* @param tparams are assumed to be the type parameters of `T`.
503-
*/
504-
final def appliedTo(args: List[Type], typParams: List[TypeParamInfo])(implicit ctx: Context): Type = {
486+
val typParams = self.typeParams
505487
def matchParams(t: Type, tparams: List[TypeParamInfo], args: List[Type])(implicit ctx: Context): Type = args match {
506488
case arg :: args1 =>
507489
try {
@@ -515,8 +497,8 @@ class TypeApplications(val self: Type) extends AnyVal {
515497
}
516498
case nil => t
517499
}
518-
assert(args.nonEmpty)
519-
self.stripTypeVar.safeDealias match {
500+
if (args.isEmpty || ctx.erasedTypes) self
501+
else self.stripTypeVar.safeDealias match {
520502
case self: TypeLambda =>
521503
if (!args.exists(_.isInstanceOf[TypeBounds])) self.instantiate(args)
522504
else {
@@ -525,14 +507,18 @@ class TypeApplications(val self: Type) extends AnyVal {
525507
if (reducer.allReplaced) reduced
526508
else HKApply(self, args)
527509
}
510+
case self: PolyType =>
511+
self.instantiate(args)
528512
case self: AndOrType =>
529513
self.derivedAndOrType(self.tp1.appliedTo(args), self.tp2.appliedTo(args))
530514
case self: TypeAlias =>
531515
self.derivedTypeAlias(self.alias.appliedTo(args))
532516
case self: TypeBounds =>
533517
self.derivedTypeBounds(self.lo, self.hi.appliedTo(args))
534518
case self: LazyRef =>
535-
LazyRef(() => self.ref.appliedTo(args, typParams))
519+
LazyRef(() => self.ref.appliedTo(args))
520+
case self: WildcardType =>
521+
self
536522
case self: TypeRef if self.symbol == defn.NothingClass =>
537523
self
538524
case _ if typParams.isEmpty || typParams.head.isInstanceOf[LambdaParam] =>
@@ -557,7 +543,7 @@ class TypeApplications(val self: Type) extends AnyVal {
557543
case self: TypeRef if !self.symbol.isClass && self.symbol.isCompleting =>
558544
HKApply(self, args)
559545
case _ =>
560-
appliedTo(args, typeParams)
546+
appliedTo(args)
561547
}
562548

563549
/** Turn this type, which is used as an argument for

0 commit comments

Comments
 (0)