scala / scala-dev

Scala 2 team issues. Not for user-facing bugs or directly actionable user-facing improvements. For build/test/infra and for longer-term planning and idea tracking. Our bug tracker is at https://github.com/scala/bug/issues
Apache License 2.0
130 stars 15 forks source link

JUnit resident compiler bug / cross-talk between tests #214

Open lrytz opened 8 years ago

lrytz commented 8 years ago

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 commented 8 years ago

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)
  }
dwijnand commented 3 years ago

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

lrytz commented 3 years ago

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.

dwijnand commented 3 years ago

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).