scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Attempt to complete Scala 3 inline method which has Scala 2 macro counterpart (MUnit) #12357

Closed bishabosha closed 3 years ago

bishabosha commented 3 years ago

This needs minimisation, but was found while trying to use MUnit 0.7.22 (with Scala 3.0.0-RC1 support). MUnit follows the advice for bundling Scala 2 macros in a Scala 3 library.

reproduction steps

using Scala 2.13.5,

// built.sbt
libraryDependencies += "org.scalameta" % "munit_3.0.0-RC1" % "0.7.22",
libraryDependencies += "org.scala-lang" % "scala-reflect" % "2.13.5",
Test / scalacOptions += "-Ydebug-tasty"
// src/test/scala/MySuite.scala
class MySuite extends munit.FunSuite {
  test("hello") {
    val obtained = 42
    val expected = 43
    assertEquals(obtained, expected)
  }
}

problem

we get the error

## Exception when compiling 1 sources to /Users/jamie/Workspace/scala2-use-scala3-libraries/munit/target/scala-2.13/test-classes
scala.reflect.internal.Types$TypeError: Unsupported Scala 3 inline method compileErrors; found in trait munit.internal.MacroCompat.CompileErrorMacro.

using -Ydebug-tasty we can see that both compileErrors methods were forced to complete, this should not happen as the Scala 3 version should have been ignored:

// ...
// completing Scala 2 macro method compileErrors 
#[class MacroCompat]: >>> trying method compileErrorsImpl: (c: scala.reflect.macros.blackbox.Context)(code: c.Tree): c.Tree
#[class MacroCompat]: >>> selected Symbol(method compileErrorsImpl, #12303): (c: scala.reflect.macros.blackbox.Context)(code: c.Tree): c.Tree
#[class MacroCompat]: Addr(1609) @@@ Symbol(macro method compileErrors, #7424).tpe =:= '[(code: String): String]; owned by trait munit.internal.MacroCompat.CompileErrorMacro
// begin completing Scala 3 inline method compileErrors
#[class MacroCompat]: Addr(1252) completing Symbol(method compileErrors, #7423) in scope Symbol(trait CompileErrorMacro, #7419)
adpi2 commented 3 years ago

A minimal reproduction of the bug can be found here: https://github.com/adpi2/scala-bug-12357

bishabosha commented 3 years ago

A minimal reproduction of the bug can be found here: https://github.com/adpi2/scala-bug-12357

Thank you! this is quite surprising that this is so small, I will investigate

som-snytt commented 3 years ago

I honestly thought from the thumbnail that @adpi2 sported an impressively huge beard, but I see when I click on it that it's actually some kind of European fungus of the sort encountered in the forests of folk tales. The younger brother heads out to seek his fortune and encounters a fungus of immense proportions and magical powers. Anyway, this bug has the quality of a folk tale, short and with profound twists.