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

currentMirror macro is unhygenic #6678

Closed
scabug opened this issue Nov 17, 2012 · 6 comments
Closed

currentMirror macro is unhygenic #6678

scabug opened this issue Nov 17, 2012 · 6 comments

Comments

@scabug
Copy link

scabug commented Nov 17, 2012

scala> object Test { object scala { reflect.runtime.currentMirror } }
<console>:7: error: value reflect is not a member of object Test.scala
       object Test { object scala { reflect.runtime.currentMirror } }
                                                    ^

Here's the offending code:

// reflect/runtime/package.scala
    def currentMirror(c: scala.reflect.macros.Context): c.Expr[universe.Mirror] = {
      import c.universe._
      val runtimeClass = c.reifyEnclosingRuntimeClass
      if (runtimeClass.isEmpty) c.abort(c.enclosingPosition, "call site does not have an enclosing class")
      val runtimeUniverse = Select(Select(Select(Ident(newTermName("scala")), newTermName("reflect")), newTermName("runtime")), newTermName("universe"))
      val currentMirror = Apply(Select(runtimeUniverse, newTermName("runtimeMirror")), List(Select(runtimeClass, newTermName("getClassLoader"))))
      c.Expr[Nothing](currentMirror)(c.WeakTypeTag.Nothing)
    }

I've seen the same problem in a few macros/compiler plugins.

@scabug
Copy link
Author

scabug commented Nov 17, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6678?orig=1
Reporter: @retronym
Assignee: @clhodapp
See #6039

@scabug
Copy link
Author

scabug commented Nov 17, 2012

@paulp said:
This problem goes far beyond macros; you can break a hundred things with an identifier named "scala". In the distant past I tried to alleviate this somewhat, and for reasons I never figured out you can't universally use root.scala as a remedy. (And not because root is a valid identifier, though obviously that is a problem as well.)

@scabug
Copy link
Author

scabug commented Nov 17, 2012

@paulp said (edited on Nov 17, 2012 3:11:29 PM UTC):
Thank you jira.

universally use _root_.scala as a remedy

@scabug
Copy link
Author

scabug commented Nov 17, 2012

@paulp said:
See also #6039.

@scabug
Copy link
Author

scabug commented Nov 17, 2012

@paulp said:
See also scala/scala@a187f432f7 aka r17172, which relates to #430.

@scabug scabug closed this as completed Jun 3, 2014
@scabug
Copy link
Author

scabug commented Jun 3, 2014

@adriaanm said:
scala/scala#3789

@scabug scabug added this to the 2.11.2 milestone Apr 7, 2017
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

1 participant