diff options
-rw-r--r-- | src/reflect/scala/reflect/runtime/ReflectionUtils.scala | 6 | ||||
-rw-r--r-- | test/files/run/macro-system-properties.check | 26 | ||||
-rw-r--r-- | test/files/run/macro-system-properties.scala | 16 |
3 files changed, 46 insertions, 2 deletions
diff --git a/src/reflect/scala/reflect/runtime/ReflectionUtils.scala b/src/reflect/scala/reflect/runtime/ReflectionUtils.scala index 7b093e0e80..2685085326 100644 --- a/src/reflect/scala/reflect/runtime/ReflectionUtils.scala +++ b/src/reflect/scala/reflect/runtime/ReflectionUtils.scala @@ -28,9 +28,11 @@ private[scala] object ReflectionUtils { case ex if pf isDefinedAt unwrapThrowable(ex) => pf(unwrapThrowable(ex)) } - private def systemProperties: Iterator[(String, String)] = { + private def systemProperties: Map[String, String] = { import scala.collection.JavaConverters._ - System.getProperties.asScala.iterator + // cannot use System.getProperties.asScala because of SI-7465 + val javaProperties: java.util.Dictionary[Object, Object] = System.getProperties + javaProperties.asScala.collect{ case (k: String, v: String) => (k, v) }.toMap } private def inferBootClasspath: String = ( diff --git a/test/files/run/macro-system-properties.check b/test/files/run/macro-system-properties.check new file mode 100644 index 0000000000..dce976df02 --- /dev/null +++ b/test/files/run/macro-system-properties.check @@ -0,0 +1,26 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> + +scala> import language.experimental._, reflect.macros.Context +import language.experimental._ +import reflect.macros.Context + +scala> object GrabContext { + def lastContext = Option(System.getProperties.get("lastContext").asInstanceOf[reflect.macros.runtime.Context]) + // System.properties lets you stash true globals (unlike statics which are classloader scoped) + def impl(c: Context)() = { System.getProperties.put("lastContext", c); c.literalUnit } + def grab() = macro impl + } +defined module GrabContext + +scala> object Test { class C(implicit a: Any) { GrabContext.grab } } +defined module Test + +scala> object Test { class C(implicit a: Any) { GrabContext.grab } } +defined module Test + +scala> + +scala> diff --git a/test/files/run/macro-system-properties.scala b/test/files/run/macro-system-properties.scala new file mode 100644 index 0000000000..e182defc81 --- /dev/null +++ b/test/files/run/macro-system-properties.scala @@ -0,0 +1,16 @@ +import scala.tools.nsc._ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ + import language.experimental._, reflect.macros.Context + object GrabContext { + def lastContext = Option(System.getProperties.get("lastContext").asInstanceOf[reflect.macros.runtime.Context]) + // System.properties lets you stash true globals (unlike statics which are classloader scoped) + def impl(c: Context)() = { System.getProperties.put("lastContext", c); c.literalUnit } + def grab() = macro impl + } + object Test { class C(implicit a: Any) { GrabContext.grab } } + object Test { class C(implicit a: Any) { GrabContext.grab } } + """ +} |