Skip to content

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

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

Closed
Linyxus opened this issue Dec 19, 2022 · 2 comments
Closed
Assignees
Labels
area:experimental:cc Capture checking related itype:bug

Comments

@Linyxus
Copy link
Contributor

Linyxus commented Dec 19, 2022

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.

@Linyxus Linyxus added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label area:experimental:cc Capture checking related labels Dec 19, 2022
@Linyxus Linyxus self-assigned this Dec 19, 2022
@Linyxus Linyxus removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Dec 19, 2022
@Linyxus Linyxus assigned Linyxus and unassigned Linyxus Dec 19, 2022
@Linyxus
Copy link
Contributor Author

Linyxus commented Dec 19, 2022

I found this when working on #16479. It seems like a caching issue of baseType. Will try to fix it in #16479.

@Linyxus
Copy link
Contributor Author

Linyxus commented Feb 6, 2023

Fixed by #16479.

@Linyxus Linyxus closed this as completed Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:experimental:cc Capture checking related itype:bug
Projects
None yet
Development

No branches or pull requests

1 participant