Skip to content
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

(caught cyclic reference) error on type definitions that works on Scala 2 #22257

Open
tribbloid opened this issue Dec 20, 2024 · 0 comments
Open
Labels
itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label

Comments

@tribbloid
Copy link

tribbloid commented Dec 20, 2024

Compiler version

3.6.2

Minimized code

The following code defined some common graph axioms:

object Scaffold {

  trait Arrow
  object Arrow {
    trait Outbound extends Arrow
  }

  trait NodeKOrGraphK {}

  trait NodeK extends NodeKOrGraphK {

    type FBound <: Induction

    protected def getInduction: Seq[FBound]
  }

  trait Induction {
    def arrow: Arrow
    def node: NodeK
  }

  object Induction {

    trait FP[+N <: NodeK] extends Induction { // short for "fixed point"
      def node: N
    }
  }

  trait GraphK extends NodeKOrGraphK {

    type Batch[+T] <: Iterable[T]

    type _Node <: NodeK

    def entries: Batch[_Node]
  }

  trait Topology {

    type FP = Induction.FP[Node]
    type FBound <: FP

    type Node = NodeK { type FBound <: Topology.this.FBound }
    trait Node_ extends NodeK {
      type FBound = Topology.this.FBound
    }

    type Graph = GraphK { type _Node <: Node }
  }

}

Output

49:10: illegal cyclic type reference: alias ai.acyclic.six.graph.Scaffold.Induction.FP[Topology.this.Node] of ... (caught cyclic reference) ... refers back to the type itself

The error occurred while trying to compute the signature of type FP
  which required to explore type Node for cyclic references
  which required to explore type FBound for cyclic references
  which required to explore type FP for cyclic references

 Run with both -explain-cyclic and -Ydebug-cyclic to see full stack trace.
one error found

FAILURE: Build failed with an exception.

Expectation

cyclic reference in sound type definition are common, but some of them are not compilable.

what makes this case interesting is that Scala 2.13 compiler has no problem compiling it.

is it an edge case of which old type exploration algorithm works better?

@tribbloid tribbloid added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label
Projects
None yet
Development

No branches or pull requests

1 participant