Skip to content

Commit 226e56b

Browse files
author
Kai
committed
Try to avoid using typedTree twice by eta-expanding manually
1 parent c6c06ce commit 226e56b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
12381238
* how class parents are handled in Namer.
12391239
*/
12401240
def typedNewTemplateParent(tree: untpd.Tree, pt: Type)(using Context): Tree =
1241-
// First type with AnyTypeConstructorProto to check if it's a HKTypeLambda
1241+
// Type with AnyTypeConstructorProto to detect type aliases (HKTypeLambda)
12421242
val parentTpt = typedType(tree, AnyTypeConstructorProto)
12431243
val ptpe = parentTpt.tpe.dealias
12441244

@@ -1254,7 +1254,13 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
12541254
val typedApp = typedExpr(app, pt)
12551255
TypeTree(typedApp.tpe).withSpan(tree.span)
12561256
case _ =>
1257-
inferTypeParams(typedType(tree), pt)
1257+
// For regular class/trait references, reuse the typed tree.
1258+
// If type has params but isn't a TypeLambda, eta-expand for inferTypeParams.
1259+
val resultTpe = parentTpt.tpe
1260+
if resultTpe.typeParams.nonEmpty && !resultTpe.isInstanceOf[TypeLambda] then
1261+
inferTypeParams(parentTpt.withType(resultTpe.etaExpand), pt)
1262+
else
1263+
inferTypeParams(parentTpt, pt)
12581264

12591265
def typedNew(tree: untpd.New, pt: Type)(using Context): Tree =
12601266
tree.tpt match {

0 commit comments

Comments
 (0)