summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2012-08-09 07:43:13 -0700
committerAdriaan Moors <adriaan.moors@epfl.ch>2012-08-09 07:43:13 -0700
commit0e2080e8bf1c54cac59c5b0c53a93eb0de009d3b (patch)
tree319d9aedfd9518d798ffbcc9add182b5e397fec2
parent5a180b7abfa806046968968226ce8cde281d6a3f (diff)
parent1dfa502280ecb126a146a3b5443e3864182dc7f9 (diff)
downloadscala-0e2080e8bf1c54cac59c5b0c53a93eb0de009d3b.tar.gz
scala-0e2080e8bf1c54cac59c5b0c53a93eb0de009d3b.tar.bz2
scala-0e2080e8bf1c54cac59c5b0c53a93eb0de009d3b.zip
Merge pull request #1094 from scalamacros/ticket/6204
fixes to existential-related reification problems
-rw-r--r--src/compiler/scala/reflect/reify/codegen/GenSymbols.scala3
-rw-r--r--src/compiler/scala/reflect/reify/utils/SymbolTables.scala21
-rw-r--r--src/reflect/scala/reflect/macros/Universe.scala22
-rw-r--r--test/files/pos/t5756.scala6
-rw-r--r--test/files/pos/t6204-a.scala9
-rw-r--r--test/files/pos/t6204-b.scala10
6 files changed, 50 insertions, 21 deletions
diff --git a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala
index 59651bcdf9..7f066a2cc3 100644
--- a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala
+++ b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala
@@ -36,7 +36,8 @@ trait GenSymbols {
else if (sym.isEmptyPackageClass)
mirrorMirrorSelect(nme.EmptyPackageClass)
else if (sym.isModuleClass)
- Select(Select(reify(sym.sourceModule), nme.asModule), nme.moduleClass)
+ if (sym.sourceModule.isLocatable) Select(Select(reify(sym.sourceModule), nme.asModule), nme.moduleClass)
+ else reifySymDef(sym)
else if (sym.isPackage)
mirrorMirrorCall(nme.staticPackage, reify(sym.fullName))
else if (sym.isLocatable) {
diff --git a/src/compiler/scala/reflect/reify/utils/SymbolTables.scala b/src/compiler/scala/reflect/reify/utils/SymbolTables.scala
index a7ac299317..3892c86dd3 100644
--- a/src/compiler/scala/reflect/reify/utils/SymbolTables.scala
+++ b/src/compiler/scala/reflect/reify/utils/SymbolTables.scala
@@ -174,15 +174,18 @@ trait SymbolTables {
if (sym.annotations.isEmpty) EmptyTree
else Apply(Select(currtab.symRef(sym), nme.setAnnotations), List(reifier.reify(sym.annotations)))
} else {
- import scala.reflect.internal.Flags._
- if (sym hasFlag LOCKED) {
- // [Eugene] better to have a symbol without a type signature, than to crash with a CyclicReference
- EmptyTree
- } else {
- val rset = reifier.mirrorBuildCall(nme.setTypeSignature, currtab.symRef(sym), reifier.reify(sym.info))
- if (sym.annotations.isEmpty) rset
- else reifier.mirrorBuildCall(nme.setAnnotations, rset, reifier.mkList(sym.annotations map reifier.reifyAnnotationInfo))
- }
+ // SI-6204 don't reify signatures for incomplete symbols, because this might lead to cyclic reference errors
+ val signature =
+ if (sym.isInitialized) {
+ if (sym.isCapturedVariable) capturedVariableType(sym)
+ else sym.info
+ } else NoType
+ val rset = reifier.mirrorBuildCall(nme.setTypeSignature, currtab.symRef(sym), reifier.reify(signature))
+ // `Symbol.annotations` doesn't initialize the symbol, so we don't need to do anything special here
+ // also since we call `sym.info` a few lines above, by now the symbol will be initialized (if possible)
+ // so the annotations will be filled in and will be waiting to be reified (unless symbol initialization is prohibited as described above)
+ if (sym.annotations.isEmpty) rset
+ else reifier.mirrorBuildCall(nme.setAnnotations, rset, reifier.mkList(sym.annotations map reifier.reifyAnnotationInfo))
}
}
diff --git a/src/reflect/scala/reflect/macros/Universe.scala b/src/reflect/scala/reflect/macros/Universe.scala
index 4074dd9e93..44a7de3d3a 100644
--- a/src/reflect/scala/reflect/macros/Universe.scala
+++ b/src/reflect/scala/reflect/macros/Universe.scala
@@ -22,17 +22,17 @@ abstract class Universe extends scala.reflect.api.Universe {
/** The extended API of symbols that's supported in macro context universes
*/
- trait SymbolContextApi extends SymbolApi with AttachableApi { this: Symbol =>
+ trait SymbolContextApi extends SymbolApi with AttachableApi { self: Symbol =>
- def setFlags(flags: FlagSet): this.type
+ def setFlags(flags: FlagSet): Symbol
- def setTypeSignature(tpe: Type): this.type
+ def setTypeSignature(tpe: Type): Symbol
- def setAnnotations(annots: AnnotationInfo*): this.type
+ def setAnnotations(annots: AnnotationInfo*): Symbol
- def setName(name: Name): this.type
+ def setName(name: Name): Symbol
- def setPrivateWithin(sym: Symbol): this.type
+ def setPrivateWithin(sym: Symbol): Symbol
}
// Tree extensions ---------------------------------------------------------------
@@ -41,20 +41,20 @@ abstract class Universe extends scala.reflect.api.Universe {
/** The extended API of trees that's supported in macro context universes
*/
- trait TreeContextApi extends TreeApi with AttachableApi { this: Tree =>
+ trait TreeContextApi extends TreeApi with AttachableApi { self: Tree =>
/** ... */
def pos_=(pos: Position): Unit
/** ... */
- def setPos(newpos: Position): this.type
+ def setPos(newpos: Position): Tree
/** ... */
def tpe_=(t: Type): Unit
/** Set tpe to give `tp` and return this.
*/
- def setType(tp: Type): this.type
+ def setType(tp: Type): Tree
/** Like `setType`, but if this is a previously empty TypeTree that
* fact is remembered so that resetAllAttrs will snap back.
@@ -73,13 +73,13 @@ abstract class Universe extends scala.reflect.api.Universe {
* and therefore should be abandoned if the current line of type
* inquiry doesn't work out.
*/
- def defineType(tp: Type): this.type
+ def defineType(tp: Type): Tree
/** ... */
def symbol_=(sym: Symbol): Unit
/** ... */
- def setSymbol(sym: Symbol): this.type
+ def setSymbol(sym: Symbol): Tree
}
override type SymTree >: Null <: Tree with SymTreeContextApi
diff --git a/test/files/pos/t5756.scala b/test/files/pos/t5756.scala
new file mode 100644
index 0000000000..45960fa8bd
--- /dev/null
+++ b/test/files/pos/t5756.scala
@@ -0,0 +1,6 @@
+import scala.reflect.runtime.universe._
+
+object Test extends App {
+ def tagme[T: TypeTag](x: T) = typeTag[T]
+ val foo = tagme{object Bar; Bar}
+} \ No newline at end of file
diff --git a/test/files/pos/t6204-a.scala b/test/files/pos/t6204-a.scala
new file mode 100644
index 0000000000..bd8d5c437e
--- /dev/null
+++ b/test/files/pos/t6204-a.scala
@@ -0,0 +1,9 @@
+import scala.reflect.runtime.universe._
+
+object Bish {
+ def m {
+ object Bash {
+ typeOf[Option[_]]
+ }
+ }
+} \ No newline at end of file
diff --git a/test/files/pos/t6204-b.scala b/test/files/pos/t6204-b.scala
new file mode 100644
index 0000000000..86094d1a19
--- /dev/null
+++ b/test/files/pos/t6204-b.scala
@@ -0,0 +1,10 @@
+import scala.reflect.runtime.universe._
+
+object Bosh {
+ def Besh {
+ new {
+ val t = typeOf[Option[_]]
+ val x = t
+ }
+ }
+} \ No newline at end of file