scala-dev icon indicating copy to clipboard operation
scala-dev copied to clipboard

JUnit resident compiler bug / cross-talk between tests

Open lrytz opened this issue 9 years ago • 4 comments
trafficstars

The following two tests in scala.tools.testkit.BytecodeTesting:

  @Test
  def eins(): Unit = {
    val code =
      """class A
        |class B extends A
        |class C extends B
      """.stripMargin
    compiler.compileClasses(code)
  }

  @Test
  def zwei(): Unit = {
    val jCode = List("interface A { }" -> "A.java")
    val code1 =
      """trait B extends A
        |class C extends B
      """.stripMargin
    compiler.compileClasses(code1, jCode)
  }

Individually they both run fine. When running them together (first eins, then zwei), we get

java.lang.AssertionError: assertion failed: The compiler issued non-allowed warnings or errors:
pos: source-unitTestSource.scala,line-2,offset=34 illegal inheritance; superclass Object
 is not a subclass of the supertrait A
 of the mixin trait B ERROR

    at scala.Predef$.assert(Predef.scala:219)
    at scala.tools.testing.Compiler.checkReport(BytecodeTesting.scala:45)
    at scala.tools.testing.Compiler.compileToBytes(BytecodeTesting.scala:52)
    at scala.tools.testing.Compiler.compileClasses(BytecodeTesting.scala:57)
    at scala.lang.traits.BytecodeTest.zwei(BytecodeTest.scala:262)

Renaming B to B1 in test zwei fixes the cross-talk. Possibly related to https://github.com/scala/scala/commit/59d6dbc.

lrytz avatar Aug 31 '16 09:08 lrytz

Here's another one:

  @Test
  def a(): Unit = {
    val jCode = List("interface T { }" -> "T.java")
    val code = "class C extends T"
    compiler.compileClasses(code, jCode)
  }

  @Test
  def b(): Unit = {
    val jCode = List("interface A { }" -> "A.java")
    val code =
      """trait T extends A
        |class C extends T
      """.stripMargin
    compiler.compileClasses(code, jCode)
  }

lrytz avatar Sep 21 '16 14:09 lrytz

Optimistically closing that this was fixed in the rework that was https://github.com/scala/scala-partest/issues/75.

dwijnand avatar Oct 23 '20 16:10 dwijnand

This ticket is not about partest, but JUnit tests that use BytecodeTesting. There we use a single Global instance and only create a new Run per test. So the test failures are symptoms of bugs in the resident compiler.

Since both still reproduce, I re-open.

lrytz avatar Oct 26 '20 13:10 lrytz

Individually they both run fine. When running them together (first eins, then zwei), we get

java.lang.AssertionError: assertion failed: The compiler issued non-allowed warnings or errors:

Perhaps due to adaptToNewRun not reverting/resetting flags (https://github.com/scala/scala/pull/9141#issuecomment-768353508).

dwijnand avatar Jan 27 '21 16:01 dwijnand