summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2013-08-28 13:53:45 -0700
committerGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2013-08-28 13:53:45 -0700
commit996a95dac9cff30313316cc6b2448ec381852042 (patch)
treecf3b901455eb909b8f01381c1fdee7ddf9f8c6ca
parent8a292cb6eed15828762ed8291c723199da5100e5 (diff)
parentd877d0cb32a1198d7b40fe0c4583b6f4f488dc52 (diff)
downloadscala-996a95dac9cff30313316cc6b2448ec381852042.tar.gz
scala-996a95dac9cff30313316cc6b2448ec381852042.tar.bz2
scala-996a95dac9cff30313316cc6b2448ec381852042.zip
Merge pull request #2847 from retronym/ticket/7501
SI-7501 Pickler: owner adjustment for param syms in annotation args
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala7
-rw-r--r--test/files/neg/t7501.check7
-rw-r--r--test/files/neg/t7501/t7501_1.scala12
-rw-r--r--test/files/neg/t7501/t7501_2.scala5
4 files changed, 30 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
index 9bad29097c..9ac1ce1b9c 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
@@ -88,12 +88,17 @@ abstract class Pickler extends SubComponent {
/** Returns usually symbol's owner, but picks classfile root instead
* for existentially bound variables that have a non-local owner.
* Question: Should this be done for refinement class symbols as well?
+ *
+ * Note: tree pickling also finds its way here; e.g. in SI-7501 the pickling
+ * of trees in annotation arguments considers the parameter symbol of a method
+ * called in such a tree as "local". The condition `sym.isValueParameter` was
+ * added to fix that bug, but there may be a better way.
*/
private def localizedOwner(sym: Symbol) =
if (isLocal(sym) && !isRootSym(sym) && !isLocal(sym.owner))
// don't use a class as the localized owner for type parameters that are not owned by a class: those are not instantiated by asSeenFrom
// however, they would suddenly be considered by asSeenFrom if their localized owner became a class (causing the crashes of #4079, #2741)
- (if(sym.isTypeParameter && !sym.owner.isClass) nonClassRoot
+ (if ((sym.isTypeParameter || sym.isValueParameter) && !sym.owner.isClass) nonClassRoot
else root)
else sym.owner
diff --git a/test/files/neg/t7501.check b/test/files/neg/t7501.check
new file mode 100644
index 0000000000..2ded07c7ed
--- /dev/null
+++ b/test/files/neg/t7501.check
@@ -0,0 +1,7 @@
+t7501_2.scala:2: error: value name is not a member of A
+ def foo(a: A) = a.name
+ ^
+t7501_2.scala:4: error: not found: type X
+ type TP = X // already failed before this fix
+ ^
+two errors found
diff --git a/test/files/neg/t7501/t7501_1.scala b/test/files/neg/t7501/t7501_1.scala
new file mode 100644
index 0000000000..323c327623
--- /dev/null
+++ b/test/files/neg/t7501/t7501_1.scala
@@ -0,0 +1,12 @@
+object Test2 {
+ def test[X](name: String) = 12
+}
+class strangeTest(x: Int) extends scala.annotation.StaticAnnotation
+
+trait A {
+ // When picking the type of `test`, the value parameter
+ // `x` was pickled with the owner `trait A`. On unpickling,
+ // it was taken to be a member!
+ @strangeTest(Test2.test("test"))
+ def test(x: String): Unit
+}
diff --git a/test/files/neg/t7501/t7501_2.scala b/test/files/neg/t7501/t7501_2.scala
new file mode 100644
index 0000000000..044caea3c3
--- /dev/null
+++ b/test/files/neg/t7501/t7501_2.scala
@@ -0,0 +1,5 @@
+object Test {
+ def foo(a: A) = a.name
+
+ type TP = X // already failed before this fix
+}