Skip to content

Fix #7820: Break cycle when computing completerTypeParams #7847

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 1 commit into from
Dec 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 18 additions & 19 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -944,28 +944,27 @@ class Namer { typer: Typer =>
private var nestedCtx: Context = null
assert(!original.isClassDef)

override def completerTypeParams(sym: Symbol)(implicit ctx: Context): List[TypeSymbol] = {
if (myTypeParams == null) {
override def completerTypeParams(sym: Symbol)(implicit ctx: Context): List[TypeSymbol] =
if myTypeParams == null then
//println(i"completing type params of $sym in ${sym.owner}")
nestedCtx = localContext(sym).setNewScope
myTypeParams = {
implicit val ctx = nestedCtx
def typeParamTrees(tdef: Tree): List[TypeDef] = tdef match {
case TypeDef(_, original) =>
original match {
case LambdaTypeTree(tparams, _) => tparams
case original: DerivedFromParamTree => typeParamTrees(original.watched)
case _ => Nil
}
case _ => Nil
}
val tparams = typeParamTrees(original)
completeParams(tparams)
tparams.map(symbolOfTree(_).asType)
}
}
given Context = nestedCtx

def typeParamTrees(tdef: Tree): List[TypeDef] = tdef match
case TypeDef(_, original) =>
original match
case LambdaTypeTree(tparams, _) => tparams
case original: DerivedFromParamTree => typeParamTrees(original.watched)
case _ => Nil
case _ => Nil

val tparams = typeParamTrees(original)
index(tparams)
myTypeParams = tparams.map(symbolOfTree(_).asType)
for param <- tparams do typedAheadExpr(param)
end if
myTypeParams
}
end completerTypeParams

override protected def typeSig(sym: Symbol): Type =
typeDefSig(original, sym, completerTypeParams(sym)(ictx))(nestedCtx)
Expand Down
3 changes: 3 additions & 0 deletions tests/neg/i7820.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trait A1 { type F[X <: F[_, _], Y] } // error: cyclic reference involving type F
trait A2 { type F[X <: F, Y] } // error: cyclic reference involving type F
trait A3 { type F[X >: F, Y] } // error: cyclic reference involving type F