Skip to content

Assert when compiling a complex combination of traits and objects #12544

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
OndrejSpanel opened this issue Mar 4, 2022 · 3 comments
Closed

Comments

@OndrejSpanel
Copy link
Member

Reproduction steps

I do not have a small repro yet, the issue is reproducible in my complex project.

Problem

When compiling the project, which is using Scala 2.13.8, I get following error:

java.lang.AssertionError: assertion failed: 
  List(object package$EntityInScene, object package$EntityInScene)
     while compiling: W:\Tempi\threeJVM\src\test\scala\net\gamatron\procas\game\state\AbstractStateTest.scala
        during phase: globalPhase=mixin, enteringPhase=cleanup

The call-stack for the assertion seems to be:

scala.reflect.internal.SymbolTable.throwAssertionError(SymbolTable.scala:171)
scala.reflect.internal.Symbols$Symbol.suchThat(Symbols.scala:2040)
scala.reflect.internal.Symbols$ClassSymbol.companionModule0(Symbols.scala:3391)
scala.reflect.internal.Symbols$ClassSymbol.companionSymbol(Symbols.scala:3394)
scala.tools.nsc.typechecker.Namers.companionSymbolOf(Namers.scala:2180)
scala.tools.nsc.typechecker.Namers.companionSymbolOf$(Namers.scala:2171)
scala.tools.nsc.transform.Erasure.companionSymbolOf(Erasure.scala:23)
scala.tools.nsc.typechecker.Namers.linkedClassOfClassOf(Namers.scala:2190)
scala.tools.nsc.typechecker.Namers.linkedClassOfClassOf$(Namers.scala:2186)
scala.tools.nsc.transform.Erasure.linkedClassOfClassOf(Erasure.scala:23)
scala.tools.nsc.typechecker.Contexts$Context.accessWithinLinked$1(Contexts.scala:910)
scala.tools.nsc.typechecker.Contexts$Context.isAccessible(Contexts.scala:965)
scala.tools.nsc.typechecker.Infer$Inferencer.$anonfun$checkAccessible$1(Infer.scala:289)
scala.tools.nsc.typechecker.Infer$Inferencer.$anonfun$checkAccessible$1$adapted(Infer.scala:289)
scala.reflect.internal.Symbols$Symbol.filter(Symbols.scala:2035)
scala.tools.nsc.typechecker.Infer$Inferencer.accessible$1(Infer.scala:289)
scala.tools.nsc.typechecker.Infer$Inferencer.checkAccessible(Infer.scala:298)
scala.tools.nsc.typechecker.Typers$Typer.makeAccessible(Typers.scala:577)
scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typed1$62(Typers.scala:5343)
scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:712)
scala.tools.nsc.typechecker.Typers$Typer.typedSelect$1(Typers.scala:5343)
scala.tools.nsc.typechecker.Typers$Typer.typedSelectOrSuperCall$1(Typers.scala:5411)
scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5986)
scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:806)
scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:6041)
scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typed1$41(Typers.scala:5074)
scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:698)
scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:5076)
scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:5104)
scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5985)
scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:806)
scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:6041)
scala.tools.nsc.typechecker.Typers$Typer.typedDefDef(Typers.scala:6318)
scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5950)
scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:806)

...

For the error to happen I need to use a source similar to (but much more complex):

package object foo {

  trait Foo {
    def f(x: Double): String
  }

  object Foo {
    trait FooA extends Foo {
      def f(x: Double): String = x.toString
    }
    trait FooB extends Foo {
      def f(x: Double): String = x.toInt.toString
    }
  }

  case class BarB() extends Foo with Foo.FooB
  case class BarA() extends Foo with Foo.FooA
}

Once I move FooA and FooB out of the the Foo companion, everything works fine.

Does this ring the bell for anyone? Is it worth spending an effort creating a proper repro?

@som-snytt
Copy link

There's a lint about not putting classes in package objects. I don't know if there is still an open ticket about the perils to which one is exposed.

@OndrejSpanel
Copy link
Member Author

I confirm when I move the object Foo out of the package object foo, and make a separate source file in the package foo for it, I get no assertion and the project compiles and runs fine.

@som-snytt
Copy link

som-snytt commented Mar 4, 2022

The old ticket with same stack trace. #5954 (asserting that the companion is not overloaded)

The open umbrella ticket wherein it is hoped that the other ticket was resolved. #4344

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants