Skip to content

Fix parameterized typedefs with lambdas as rhs #1409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -934,15 +934,11 @@ class Namer { typer: Typer =>
}

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

val dummyInfo = abstracted(TypeBounds.empty)
val dummyInfo = abstracted(TypeBounds.empty, canAbstract = true)
sym.info = dummyInfo
// Temporarily set info of defined type T to ` >: Nothing <: Any.
// This is done to avoid cyclic reference errors for F-bounds.
Expand All @@ -954,7 +950,9 @@ class Namer { typer: Typer =>
//
// The scheme critically relies on an implementation detail of isRef, which
// inspects a TypeRef's info, instead of simply dealiasing alias types.
val rhsType = abstracted(typedAheadType(tdef.rhs).tpe)

val isDerived = tdef.rhs.isInstanceOf[untpd.DerivedTypeTree]
val rhsType = abstracted(typedAheadType(tdef.rhs).tpe, canAbstract = !isDerived)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a boolean parameter that changes the behavior of a method to become the identity seems weird to me, I would just write:

val rhsType0 = typedAheadType(tdef.rhs).tpe
val rhsType = if (!isDerived) abstracted(rhsType0) else rhsType0

val unsafeInfo = rhsType match {
case bounds: TypeBounds => bounds
case alias => TypeAlias(alias, if (sym is Local) sym.variance else 0)
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/nestedLambdas.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Test {

type T = [X] -> [Y] -> (X, Y)

type A[X] = [Y] -> (X, Y)

type B[X] = (X, X)

}