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

Checking for a WeakTypeTag in macro implementation parameters under -Xsource:2.10 #8461

Closed
scabug opened this issue Mar 28, 2014 · 7 comments

Comments

@scabug
Copy link

scabug commented Mar 28, 2014

When looking at a macro implementation, the compiler looks at parameters to recognize, among other less semantic sanity-checks, that the only implicit parameter is a WeakTypeTag.

This is done in scala.reflect.macros.compiler's Validators, through the building of macroImplSig. The exact place of comparison is in scala.reflect.macros.util.Helpers' transformTypeTagEvidenceParams.
If it fails you get a MacroImplNonTagImplicitParameters.

But from what I understand, the WeakTypeTagClass being compared against is (scala-)version-specific, so that when the 2.11 compiler works in -Xsource:2.10 mode, against a macro implementation coming from a 2.10 classfile, the WeakTypeTagClass it should try to find an instance of is not the one it has loaded, but the one in the 2.10 scala-reflect jar it (hopefully has on classpath).

So the symptom is, when compiling the play framework on 2.10 with -Xsource:2.10 and -Ymacro-expand:none:

/home/huitseeker/Scala/playframework/framework/src/play-json/src/main/scala/play/api/libs/json/Json.scala:194: error: macro implementations cannot have implicit parameters other than WeakTypeTag evidences
  def reads[A] = macro JsMacroImpl.readsImpl[A]
                                   ^
/home/huitseeker/Scala/playframework/framework/src/play-json/src/main/scala/play/api/libs/json/Json.scala:214: error: macro implementations cannot have implicit parameters other than WeakTypeTag evidences
  def writes[A] = macro JsMacroImpl.writesImpl[A]
                                    ^
/home/huitseeker/Scala/playframework/framework/src/play-json/src/main/scala/play/api/libs/json/Json.scala:234: error: macro implementations cannot have implicit parameters other than WeakTypeTag evidences
  def format[A] = macro JsMacroImpl.formatImpl[A]
                                    ^
three errors found

The relevant signatures from JsMacroImpl are fine:

  def readsImpl[A: c.WeakTypeTag](c: Context): c.Expr[Reads[A]] = {
  def writesImpl[A: c.WeakTypeTag](c: Context): c.Expr[Writes[A]] = {
  def formatImpl[A: c.WeakTypeTag](c: Context): c.Expr[Format[A]] = {

Is there a way for transformTag to dereference the class and manually fetch that 2.10 WeakTypeTagClass from classpath to compare against ?

@scabug
Copy link
Author

scabug commented Mar 28, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8461?orig=1
Reporter: @huitseeker
Affected Versions: 2.11.0-RC3
See #8402

@scabug
Copy link
Author

scabug commented Mar 28, 2014

@retronym said:
Worst case you could just disable that check altogether under this mode.

@scabug
Copy link
Author

scabug commented Mar 28, 2014

@huitseeker said:
The resources to reproduce the play framework failure:
https://github.com/huitseeker/Xsource-nightlies contains a single script, building.sh, tailored to succeed despite the above limitation. To witness it, comment line 74 (the line that contains the string Json.scala), and run it from the framework directory of a playframework checkout.

@scabug
Copy link
Author

scabug commented Mar 28, 2014

@xeno-by said:
We could probably patch transformTag to respect -Xsource. Wdyt, Jason? Are we going to make it into 2.11.0?

@scabug
Copy link
Author

scabug commented Apr 3, 2014

@huitseeker said:
Pinging @retronym.

@scabug
Copy link
Author

scabug commented Apr 3, 2014

@retronym said:
Steps to repro:

cat test/files/pos/t8461/Impl.scala
import reflect.macros.Context
import language.experimental._

object Macro {
  def readsImpl[A: c.WeakTypeTag](c: Context): c.Expr[Unit] = c.literalUnit
  def reads[A] = macro readsImpl[A]
}

  ~/code/scala (qbin/scalac -nobootcp -Dscala.usejavacp=false -Xsource:2.10 -classpath $HOME/.m2/repository/org/scala-lang/scala-library/2.10.3/scala-library-2.10.3.jar:$HOME/.m2/repository/org/scala-lang/scala-reflect/2.10.3/scala-reflect-2.10.3.jar test/files/pos/t8461/Impl.scala )
test/files/pos/t8461/Impl.scala:6: error: macro implementations cannot have implicit parameters other than WeakTypeTag evidences
  def reads[A] = macro readsImpl[A]
                       ^
one error found

What we need to do is make the looks for whitebox.Context fallback to Context.

@scabug
Copy link
Author

scabug commented Apr 3, 2014

@retronym said:
scala/scala#3673

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