Skip to content

Commit 1e30c39

Browse files
committed
Fix #9000: Change definition of isTrivial
The only difference between checking cyclicity of a match type in an object O and on the toplevel is that the matchtype itself has the prefix O.this in the first case, and TermRef(_, pkgObject) in the second case (this is because the match type is actually looked up in the package scope, not in the package object scope). This made a difference in the isTrivial check when computing type parameters. And this in turn caused spurious cycles to be reported. The fix is to add the missing case to isTrivial.
1 parent aa1c363 commit 1e30c39

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

compiler/src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Decorators._
1010
import util.Stats._
1111
import Names._
1212
import NameOps._
13+
import Flags.Module
1314
import Variances.variancesConform
1415
import dotty.tools.dotc.config.Config
1516

@@ -145,7 +146,11 @@ class TypeApplications(val self: Type) extends AnyVal {
145146
final def typeParams(implicit ctx: Context): List[TypeParamInfo] = {
146147
record("typeParams")
147148
def isTrivial(prefix: Type, tycon: Symbol) = prefix match {
148-
case prefix: ThisType => prefix.cls `eq` tycon.owner
149+
case prefix: ThisType =>
150+
prefix.cls eq tycon.owner
151+
case prefix: TermRef =>
152+
val sym = prefix.symbol
153+
sym.is(Module) && sym.isStatic && (sym.moduleClass eq tycon.owner)
149154
case NoPrefix => true
150155
case _ => false
151156
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
type A = B // error: recursion limit exceeded
2-
1+
type A = B

tests/pos/toplevel-match.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class A
2+
class B
3+
4+
trait HList
5+
class HCons[A, As <: HList] extends HList
6+
class HNil[A] extends HList
7+
8+
type AtoB[Xs <: HList] <: HList = Xs match
9+
case HNil[a] => HNil[B]
10+
case HCons[a, as] => HCons[B, AtoB[as]]
11+
12+
//type A2B[Xs <: Tuple] <: Tuple = Xs match
13+
// case Unit => Unit
14+
// case a *: as => B *: A2B[as]

0 commit comments

Comments
 (0)