Skip to content

Cyclic reference involving type X #10967

Closed
@marcus-nl

Description

@marcus-nl

Using dotty M3 and also the current master branch.

Minimized code

trait SomeTrait

trait CollBase[A <: SomeTrait, +CC[A2 <: SomeTrait]] {
  val companion: CollCompanion[CC]
}

trait Coll[A <: SomeTrait] extends CollBase[A, Coll]

trait CollCompanion[+CC[A <: SomeTrait]]

(Simplified from Graph for Scala's GraphCompanion, GraphBase, EdgeLike, etc)

Output

-- [E046] Cyclic Error: tests/pos/cyclic-type-var.scala:70:29 ------------------
70 |trait CollCompanion[+CC[A <: SomeTrait]]
   |                             ^
   |                             Cyclic reference involving type CC

longer explanation available when compiling with `-explain`
-- [E046] Cyclic Error: tests/pos/cyclic-type-var.scala:70:19 ------------------
70 |trait CollCompanion[+CC[A <: SomeTrait]]
   |                   ^
   |                   Cyclic reference involving method <init>

Expectation

A similar case without the restriction A <: SomeTrait does work:

trait CollBase[A, +CC[_]] {
  val companion: CollCompanion[CC]
}

trait Coll[A] extends CollBase[A, Coll]

trait CollCompanion[+CC[_]]

I don't understand why the restriction would cause a cyclic reference. Seems like a bug to me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions