Skip to content

Commit 996a95d

Browse files
committed
Merge pull request scala#2847 from retronym/ticket/7501
SI-7501 Pickler: owner adjustment for param syms in annotation args
2 parents 8a292cb + d877d0c commit 996a95d

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,17 @@ abstract class Pickler extends SubComponent {
8888
/** Returns usually symbol's owner, but picks classfile root instead
8989
* for existentially bound variables that have a non-local owner.
9090
* Question: Should this be done for refinement class symbols as well?
91+
*
92+
* Note: tree pickling also finds its way here; e.g. in SI-7501 the pickling
93+
* of trees in annotation arguments considers the parameter symbol of a method
94+
* called in such a tree as "local". The condition `sym.isValueParameter` was
95+
* added to fix that bug, but there may be a better way.
9196
*/
9297
private def localizedOwner(sym: Symbol) =
9398
if (isLocal(sym) && !isRootSym(sym) && !isLocal(sym.owner))
9499
// 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
95100
// however, they would suddenly be considered by asSeenFrom if their localized owner became a class (causing the crashes of #4079, #2741)
96-
(if(sym.isTypeParameter && !sym.owner.isClass) nonClassRoot
101+
(if ((sym.isTypeParameter || sym.isValueParameter) && !sym.owner.isClass) nonClassRoot
97102
else root)
98103
else sym.owner
99104

test/files/neg/t7501.check

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
t7501_2.scala:2: error: value name is not a member of A
2+
def foo(a: A) = a.name
3+
^
4+
t7501_2.scala:4: error: not found: type X
5+
type TP = X // already failed before this fix
6+
^
7+
two errors found

test/files/neg/t7501/t7501_1.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Test2 {
2+
def test[X](name: String) = 12
3+
}
4+
class strangeTest(x: Int) extends scala.annotation.StaticAnnotation
5+
6+
trait A {
7+
// When picking the type of `test`, the value parameter
8+
// `x` was pickled with the owner `trait A`. On unpickling,
9+
// it was taken to be a member!
10+
@strangeTest(Test2.test("test"))
11+
def test(x: String): Unit
12+
}

test/files/neg/t7501/t7501_2.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
def foo(a: A) = a.name
3+
4+
type TP = X // already failed before this fix
5+
}

0 commit comments

Comments
 (0)