Skip to content

Commit 5968e9f

Browse files
committed
Fix parameterized typedefs with lambdas as rhs
Previously the compiler crashed when faced with a parameterized typedef that has a lambda as rhs. We fix this by refining the condition when not to abstract in typeDefsig.
1 parent 80a65f4 commit 5968e9f

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -934,15 +934,11 @@ class Namer { typer: Typer =>
934934
}
935935

936936
def typeDefSig(tdef: TypeDef, sym: Symbol, tparamSyms: List[TypeSymbol])(implicit ctx: Context): Type = {
937-
val isDerived = tdef.rhs.isInstanceOf[untpd.DerivedTypeTree]
938-
//val toParameterize = tparamSyms.nonEmpty && !isDerived
939-
//val needsLambda = sym.allOverriddenSymbols.exists(_ is HigherKinded) && !isDerived
940-
def abstracted(tp: Type): Type =
941-
if (tparamSyms.nonEmpty && !tp.isHK) tp.LambdaAbstract(tparamSyms)
942-
//else if (toParameterize) tp.parameterizeWith(tparamSyms)
937+
def abstracted(tp: Type, canAbstract: Boolean): Type =
938+
if (tparamSyms.nonEmpty && canAbstract) tp.LambdaAbstract(tparamSyms)
943939
else tp
944940

945-
val dummyInfo = abstracted(TypeBounds.empty)
941+
val dummyInfo = abstracted(TypeBounds.empty, canAbstract = true)
946942
sym.info = dummyInfo
947943
// Temporarily set info of defined type T to ` >: Nothing <: Any.
948944
// This is done to avoid cyclic reference errors for F-bounds.
@@ -954,7 +950,9 @@ class Namer { typer: Typer =>
954950
//
955951
// The scheme critically relies on an implementation detail of isRef, which
956952
// inspects a TypeRef's info, instead of simply dealiasing alias types.
957-
val rhsType = abstracted(typedAheadType(tdef.rhs).tpe)
953+
954+
val isDerived = tdef.rhs.isInstanceOf[untpd.DerivedTypeTree]
955+
val rhsType = abstracted(typedAheadType(tdef.rhs).tpe, canAbstract = !isDerived)
958956
val unsafeInfo = rhsType match {
959957
case bounds: TypeBounds => bounds
960958
case alias => TypeAlias(alias, if (sym is Local) sym.variance else 0)

tests/pos/nestedLambdas.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Test {
2+
3+
type T = [X] -> [Y] -> (X, Y)
4+
5+
type A[X] = [Y] -> (X, Y)
6+
7+
type B[X] = (X, X)
8+
9+
}

0 commit comments

Comments
 (0)