Skip to content

Fix #9000: Avoid spurious cyclic errors for toplevel matches #9001

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
May 19, 2020
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
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Decorators._
import util.Stats._
import Names._
import NameOps._
import Flags.Module
import Variances.variancesConform
import dotty.tools.dotc.config.Config

Expand Down Expand Up @@ -145,7 +146,11 @@ class TypeApplications(val self: Type) extends AnyVal {
final def typeParams(implicit ctx: Context): List[TypeParamInfo] = {
record("typeParams")
def isTrivial(prefix: Type, tycon: Symbol) = prefix match {
case prefix: ThisType => prefix.cls `eq` tycon.owner
case prefix: ThisType =>
prefix.cls eq tycon.owner
case prefix: TermRef =>
val sym = prefix.symbol
sym.is(Module) && sym.isStatic && (sym.moduleClass eq tycon.owner)
case NoPrefix => true
case _ => false
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ class CyclicReference private (val denot: SymDenotation) extends TypeError {
object CyclicReference {
def apply(denot: SymDenotation)(implicit ctx: Context): CyclicReference = {
val ex = new CyclicReference(denot)
if (!(ctx.mode is Mode.CheckCyclic)) {
cyclicErrors.println(s"Cyclic reference involving $denot")
if (!(ctx.mode is Mode.CheckCyclic) || ctx.settings.Ydebug.value) {
cyclicErrors.println(s"Cyclic reference involving! $denot")
for (elem <- ex.getStackTrace take 200)
cyclicErrors.println(elem.toString)
}
Expand Down
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2238,7 +2238,11 @@ object messages {

class IllegalCyclicTypeReference(sym: Symbol, where: String, lastChecked: Type)(using ctx: Context)
extends CyclicMsg(IllegalCyclicTypeReferenceID) {
def msg = i"illegal cyclic type reference: ${where} ${hl(lastChecked.show)} of $sym refers back to the type itself"
def msg =
val lastCheckedStr =
try lastChecked.show
catch case ex: CyclicReference => "..."
i"illegal cyclic type reference: ${where} ${hl(lastCheckedStr)} of $sym refers back to the type itself"
def explain = ""
}

Expand Down
3 changes: 1 addition & 2 deletions tests/neg/toplevel-cyclic/defs_1.scala
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
type A = B // error: recursion limit exceeded

type A = B
14 changes: 14 additions & 0 deletions tests/pos/toplevel-match.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class A
class B

trait HList
class HCons[A, As <: HList] extends HList
class HNil[A] extends HList

type AtoB[Xs <: HList] <: HList = Xs match
case HNil[a] => HNil[B]
case HCons[a, as] => HCons[B, AtoB[as]]

//type A2B[Xs <: Tuple] <: Tuple = Xs match
// case Unit => Unit
// case a *: as => B *: A2B[as]