Skip to content

Commit 15e60e8

Browse files
committed
Narrow matches from TypeLambda to HKTypeLambda where appropriate
1 parent 8d33ca7 commit 15e60e8

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
@@ -215,7 +215,7 @@ class TypeApplications(val self: Type) extends AnyVal {
215215
self match {
216216
case self: ClassInfo =>
217217
self.cls.typeParams
218-
case self: TypeLambda =>
218+
case self: HKTypeLambda =>
219219
self.typeParams
220220
case self: TypeRef =>
221221
val tsym = self.symbol
@@ -386,7 +386,7 @@ class TypeApplications(val self: Type) extends AnyVal {
386386
val dealiased = stripped.safeDealias
387387
if (args.isEmpty || ctx.erasedTypes) self
388388
else dealiased match {
389-
case dealiased: TypeLambda =>
389+
case dealiased: HKTypeLambda =>
390390
def tryReduce =
391391
if (!args.exists(_.isInstanceOf[TypeBounds])) {
392392
val followAlias = Config.simplifyApplications && {
@@ -414,6 +414,8 @@ class TypeApplications(val self: Type) extends AnyVal {
414414
else HKApply(dealiased, args)
415415
}
416416
tryReduce
417+
case dealiased: PolyType =>
418+
dealiased.instantiate(args)
417419
case dealiased: AndOrType =>
418420
dealiased.derivedAndOrType(dealiased.tp1.appliedTo(args), dealiased.tp2.appliedTo(args))
419421
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 _ =>
@@ -2830,7 +2830,7 @@ object Types {
28302830
override def superType(implicit ctx: Context): Type = {
28312831
if (ctx.period != validSuper) {
28322832
cachedSuper = tycon match {
2833-
case tp: TypeLambda => defn.AnyType
2833+
case tp: HKTypeLambda => defn.AnyType
28342834
case tp: TypeVar if !tp.inst.exists =>
28352835
// supertype not stable, since underlying might change
28362836
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)