Skip to content

Commit 3f8ad70

Browse files
committed
Narrow matches from TypeLambda to HKTypeLambda where appropriate
1 parent 617e2e7 commit 3f8ad70

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class TypeApplications(val self: Type) extends AnyVal {
214214
self match {
215215
case self: ClassInfo =>
216216
self.cls.typeParams
217-
case self: TypeLambda =>
217+
case self: HKTypeLambda =>
218218
self.typeParams
219219
case self: TypeRef =>
220220
val tsym = self.symbol
@@ -385,7 +385,7 @@ class TypeApplications(val self: Type) extends AnyVal {
385385
val dealiased = stripped.safeDealias
386386
if (args.isEmpty || ctx.erasedTypes) self
387387
else dealiased match {
388-
case dealiased: TypeLambda =>
388+
case dealiased: HKTypeLambda =>
389389
def tryReduce =
390390
if (!args.exists(_.isInstanceOf[TypeBounds])) {
391391
val followAlias = Config.simplifyApplications && {
@@ -413,6 +413,8 @@ class TypeApplications(val self: Type) extends AnyVal {
413413
else HKApply(dealiased, args)
414414
}
415415
tryReduce
416+
case dealiased: PolyType =>
417+
dealiased.instantiate(args)
416418
case dealiased: AndOrType =>
417419
dealiased.derivedAndOrType(dealiased.tp1.appliedTo(args), dealiased.tp2.appliedTo(args))
418420
case dealiased: TypeAlias =>

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
430430
compareHkApply2(tp1, tp2, tycon2, args2)
431431
case tp2: HKTypeLambda =>
432432
def compareTypeLambda: Boolean = tp1.stripTypeVar match {
433-
case tp1: TypeLambda =>
433+
case tp1: HKTypeLambda =>
434434
/* Don't compare bounds of lambdas under language:Scala2, or t2994 will fail
435435
* The issue is that, logically, bounds should compare contravariantly,
436436
* but that would invalidate a pattern exploited in t2994:

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ object Types {
539539
}
540540

541541
def goApply(tp: HKApply) = tp.tycon match {
542-
case tl: TypeLambda =>
542+
case tl: HKTypeLambda =>
543543
go(tl.resType).mapInfo(info =>
544544
tl.derivedLambdaAbstraction(tl.paramNames, tl.paramInfos, info).appliedTo(tp.args))
545545
case _ =>
@@ -2826,7 +2826,7 @@ object Types {
28262826
override def superType(implicit ctx: Context): Type = {
28272827
if (ctx.period != validSuper) {
28282828
cachedSuper = tycon match {
2829-
case tp: TypeLambda => defn.AnyType
2829+
case tp: HKTypeLambda => defn.AnyType
28302830
case tp: TypeVar if !tp.inst.exists =>
28312831
// supertype not stable, since underlying might change
28322832
return tp.underlying.applyIfParameterized(args)

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ object Inferencing {
121121

122122
/** If `tree` has a type lambda type, infer its type parameters by comparing with expected type `pt` */
123123
def inferTypeParams(tree: Tree, pt: Type)(implicit ctx: Context): Tree = tree.tpe match {
124-
case poly: TypeLambda =>
125-
val (poly1, tvars) = constrained(poly, tree)
126-
val tree1 = tree.withType(poly1).appliedToTypeTrees(tvars)
124+
case tl: TypeLambda =>
125+
val (tl1, tvars) = constrained(tl, tree)
126+
val tree1 = tree.withType(tl1).appliedToTypeTrees(tvars)
127127
tree1.tpe <:< pt
128128
fullyDefinedType(tree1.tpe, "template parent", tree.pos)
129129
tree1

0 commit comments

Comments
 (0)