Skip to content
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

Signature is different if method compiled by Scala 2 #11949

Closed
bishabosha opened this issue Mar 30, 2021 · 2 comments
Closed

Signature is different if method compiled by Scala 2 #11949

bishabosha opened this issue Mar 30, 2021 · 2 comments
Assignees

Comments

@bishabosha
Copy link
Member

bishabosha commented Mar 30, 2021

Compiler version

3.0.0-RC2

Minimized code

// reflection.scala (scala-reflect shim), compiled with Scala 2.13.5
package reflectshims

abstract class Universe {
  type Tree >: Null <: AnyRef with TreeApi
  trait TreeApi extends Product { this: Tree => }
}

trait Context {

  type Tree = universe.Tree

  val universe: Universe

}
// Scala2Macros.scala
package example

object Scala2Macro {
  def fooImpl(c: reflectshims.Context)(code: c.Tree): c.Tree = code
}

class Scala2Bundle(val c: reflectshims.Context) {
  def fooImpl(code: c.Tree): c.Tree = code
}
// MacroDefs.scala, compile with 3.0.0-RC2
package example

object MacroDefs {
  // here we simulate code generated for Scala 2 macro implementations

  def foo(code: String): String = Scala2Macro.fooImpl(??? : reflectshims.Context)(???).asInstanceOf[String]

  def foo2(code: String): String = {
    val bundle = new Scala2Bundle(null)
    bundle.fooImpl(???).asInstanceOf[String]
  }

}

Output

  • compile Scala2Macros.scala with 2.13.5
  • compile MacroDefs.scala
  • the signature in TASTy for calling Scala2Macro.fooImpl is
fooImpl[Signed Signature(List(reflectshims.Context, reflectshims.Universe.TreeApi),reflectshims.Universe.TreeApi) @fooImpl]
  • compile Scala2Macros.scala with 3.0.0-RC2
  • compile MacroDefs.scala
  • the signature in TASTy for calling Scala2Macro.fooImpl is
fooImpl[Signed Signature(List(reflectshims.Context, java.lang.Object),java.lang.Object) @fooImpl]

Expectation

I expect the signature to be the same

@bishabosha
Copy link
Member Author

bishabosha commented Mar 30, 2021

I am not so sure yet what is the cause of this thing, if it is an expected change specifically for Scala 3 compiled methods I would like to try and replicate the new erasure rules in Scala 2, e.g. probably related to #11603, #11808

@bishabosha
Copy link
Member Author

bishabosha commented Mar 30, 2021

In fact now I have seen that the bytecode signatures also change when compiled by Scala 2.13.5 vs Scala 3.0.0-RC2 this seems expected

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

No branches or pull requests

2 participants