diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-12-14 14:49:01 -0800 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-12-14 14:49:01 -0800 |
commit | 14aa26ca0c346adbc79ccf4c0c9c35bbdd80c201 (patch) | |
tree | 2c4c54164237a80459b6aaaa01380dad70b9cdfc | |
parent | a29293c8bc22b8a68b1033a440db14af49501f56 (diff) | |
parent | 098e8a084adbebca1f2e57e1aacbf6d9a3a87e7d (diff) | |
download | scala-14aa26ca0c346adbc79ccf4c0c9c35bbdd80c201.tar.gz scala-14aa26ca0c346adbc79ccf4c0c9c35bbdd80c201.tar.bz2 scala-14aa26ca0c346adbc79ccf4c0c9c35bbdd80c201.zip |
Merge pull request #1766 from scalamacros/topic/typed-ident-attachments
typedIdent no longer destroys attachments
6 files changed, 24 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 454b03c9b3..e4744de1b8 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -5155,7 +5155,7 @@ trait Typers extends Modes with Adaptations with Tags { val tree1 = ( if (qual == EmptyTree) tree // atPos necessary because qualifier might come from startContext - else atPos(tree.pos)(Select(qual, name)) + else atPos(tree.pos)(Select(qual, name) setAttachments tree.attachments) ) val (tree2, pre2) = makeAccessible(tree1, defSym, pre, qual) // assert(pre.typeArgs isEmpty) // no need to add #2416-style check here, right? diff --git a/src/reflect/scala/reflect/internal/StdAttachments.scala b/src/reflect/scala/reflect/internal/StdAttachments.scala index 1df91a67b0..b782353ed3 100644 --- a/src/reflect/scala/reflect/internal/StdAttachments.scala +++ b/src/reflect/scala/reflect/internal/StdAttachments.scala @@ -10,6 +10,7 @@ trait StdAttachments { trait Attachable { protected var rawatt: scala.reflect.macros.Attachments { type Pos = Position } = NoPosition def attachments = rawatt + def setAttachments(attachments: scala.reflect.macros.Attachments { type Pos = Position }): this.type = { rawatt = attachments; this } def updateAttachment[T: ClassTag](attachment: T): this.type = { rawatt = rawatt.update(attachment); this } def removeAttachment[T: ClassTag]: this.type = { rawatt = rawatt.remove[T]; this } diff --git a/test/files/pos/attachments-typed-ident.check b/test/files/pos/attachments-typed-ident.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/pos/attachments-typed-ident.check diff --git a/test/files/pos/attachments-typed-ident.flags b/test/files/pos/attachments-typed-ident.flags new file mode 100644 index 0000000000..cd66464f2f --- /dev/null +++ b/test/files/pos/attachments-typed-ident.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/test/files/pos/attachments-typed-ident/Impls_1.scala b/test/files/pos/attachments-typed-ident/Impls_1.scala new file mode 100644 index 0000000000..cc40893a93 --- /dev/null +++ b/test/files/pos/attachments-typed-ident/Impls_1.scala @@ -0,0 +1,17 @@ +import scala.reflect.macros.Context +import language.experimental.macros + +object MyAttachment + +object Macros { + def impl(c: Context) = { + import c.universe._ + val ident = Ident(newTermName("bar")) updateAttachment MyAttachment + assert(ident.attachments.get[MyAttachment.type].isDefined, ident.attachments) + val typed = c.typeCheck(ident) + assert(typed.attachments.get[MyAttachment.type].isDefined, typed.attachments) + c.Expr[Int](typed) + } + + def foo = macro impl +}
\ No newline at end of file diff --git a/test/files/pos/attachments-typed-ident/Macros_Test_2.scala b/test/files/pos/attachments-typed-ident/Macros_Test_2.scala new file mode 100644 index 0000000000..37065ead4b --- /dev/null +++ b/test/files/pos/attachments-typed-ident/Macros_Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + def bar = 2 + Macros.foo +}
\ No newline at end of file |