summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2014-01-27 17:25:16 +0300
committerEugene Burmako <xeno.by@gmail.com>2014-02-15 09:23:58 +0100
commit1dda1760113f782ffbcf10f0ca7b9e4f8817a62a (patch)
treebe926837dc9b6afd0c02ca3d536b1051e3e810d2 /test/files/run
parentd7b6662ddd346d0a4dc12ea62a3392ac176bf271 (diff)
downloadscala-1dda1760113f782ffbcf10f0ca7b9e4f8817a62a.tar.gz
scala-1dda1760113f782ffbcf10f0ca7b9e4f8817a62a.tar.bz2
scala-1dda1760113f782ffbcf10f0ca7b9e4f8817a62a.zip
SI-7044 deprecates Symbol.associatedFile
Before this commit, Symbol.associatedFile used to be broken in two ways. Firstly, it was never autoloaded (just like we used to have flags, privateWithin and annotations). Secondly, it was never filled in by runtime reflection. My first attempt at fixing those problems was, well, just fixing them. However, its runtime implementation was based on a hacky function that we were not very much excited about supported (see comments), whereas its compile-time usefulness was somewhat questionable. Therefore the second attempt at fixing this bug is deprecating the API altogether, replacing it with `Symbol.pos.source`. Since `Symbol.pos` isn't retained for runtime consumption, `Symbol.pos.source` is still going to return `NoAbstractFile` as before this commit, but that's left for future work, and suggested approach is documented in SI-8259.
Diffstat (limited to 'test/files/run')
-rw-r--r--test/files/run/t7044.check14
-rw-r--r--test/files/run/t7044/Macros_1.scala26
-rw-r--r--test/files/run/t7044/Test_2.scala19
3 files changed, 59 insertions, 0 deletions
diff --git a/test/files/run/t7044.check b/test/files/run/t7044.check
new file mode 100644
index 0000000000..ab523873bf
--- /dev/null
+++ b/test/files/run/t7044.check
@@ -0,0 +1,14 @@
+compile-time
+uninitialized File: <no file>
+initialized File: <no file>
+uninitialized BitSet: <no file>
+initialized BitSet: <no file>
+uninitialized C: Test_2.scala
+initialized C: Test_2.scala
+runtime
+autoinitialized File: <no file> true
+autoinitialized File: <no file> true
+autoinitialized BitSet: <no file> true
+autoinitialized BitSet: <no file> true
+autoinitialized C: <no file> true
+autoinitialized C: <no file> true
diff --git a/test/files/run/t7044/Macros_1.scala b/test/files/run/t7044/Macros_1.scala
new file mode 100644
index 0000000000..3b3f8c3385
--- /dev/null
+++ b/test/files/run/t7044/Macros_1.scala
@@ -0,0 +1,26 @@
+import scala.reflect.macros.whitebox._
+import scala.language.experimental.macros
+
+object Macros {
+ def impl(c: Context) = {
+ var messages = List[String]()
+ def println(msg: String) = messages :+= msg
+
+ import c.universe._
+ def test(tpe: Type): Unit = {
+ val sym = tpe.typeSymbol
+ println(s"uninitialized ${sym.name}: ${sym.pos.source.file.name}")
+ internal.initialize(sym)
+ println(s"initialized ${sym.name}: ${sym.pos.source.file.name}")
+ }
+
+ println("compile-time")
+ test(typeOf[java.io.File])
+ test(typeOf[scala.collection.BitSet])
+ test(c.mirror.staticClass("C").toType)
+
+ q"..${messages.map(msg => q"println($msg)")}"
+ }
+
+ def foo: Any = macro impl
+} \ No newline at end of file
diff --git a/test/files/run/t7044/Test_2.scala b/test/files/run/t7044/Test_2.scala
new file mode 100644
index 0000000000..8dfb349086
--- /dev/null
+++ b/test/files/run/t7044/Test_2.scala
@@ -0,0 +1,19 @@
+import scala.reflect.runtime.universe._
+import scala.reflect.runtime.{currentMirror => cm}
+
+class C
+
+object Test extends App {
+ def test(tpe: Type): Unit = {
+ val sym = tpe.typeSymbol
+ println(s"autoinitialized ${sym.name}: ${sym.pos.source.file.name} ${sym.pos.source.file.sizeOption.nonEmpty}")
+ internal.initialize(sym)
+ println(s"autoinitialized ${sym.name}: ${sym.pos.source.file.name} ${sym.pos.source.file.sizeOption.nonEmpty}")
+ }
+
+ Macros.foo
+ println("runtime")
+ test(typeOf[java.io.File])
+ test(typeOf[scala.collection.BitSet])
+ test(typeOf[C])
+}