Skip to content

Spurious inheritance conflict error when capture-checking impure classes #16553

Closed
@Linyxus

Description

@Linyxus

Compiler version

main

Minimized code

import language.experimental.captureChecking
trait Ctx
type Context = {*} Ctx

trait Type

abstract class TypeAccumulator[T](implicit protected val accCtx: Context) {
  this: {*} TypeAccumulator[T] =>
  def apply(x: T, tp: Type): T
  def foldOver(x: T, tp: Type): T = ???
}

abstract class TypeTraverser(using Context) extends TypeAccumulator[Unit] {
  def traverse(tp: Type): Unit
  def apply(x: Unit, tp: Type): Unit = traverse(tp)
  protected def traverseChildren(tp: Type): Unit = foldOver((), tp)
}

def main(using ctx: Context): Unit = {
  val checker = new TypeTraverser { this: {ctx} TypeTraverser =>
    def traverse(tp: Type): Unit = ???
  }
}

Output

20 |  val checker = new TypeTraverser { this: {ctx} TypeTraverser =>
   |                ^
   |                illegal inheritance: anonymous class TypeTraverser {...} inherits conflicting instances of parameterized base class TypeAccumulator.
   |
   |                  Direct basetype: TypeAccumulator[Unit]
   |                  Basetype via superclass TypeTraverser: {ctx} TypeAccumulator[Unit]
1 error found

Expectation

This code should compile.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions