summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-01-20 01:12:58 +0100
committerJason Zaugg <jzaugg@gmail.com>2013-01-26 14:29:08 +0100
commitcff09340327ddcfd3d39aca69dfb719e7a501b5f (patch)
treeb4adee0ca1dbe08b72587656ab814ff0f4f32412 /src/reflect
parent05ad68203a2a54973f77e8dc03757a3d0812182c (diff)
downloadscala-cff09340327ddcfd3d39aca69dfb719e7a501b5f.tar.gz
scala-cff09340327ddcfd3d39aca69dfb719e7a501b5f.tar.bz2
scala-cff09340327ddcfd3d39aca69dfb719e7a501b5f.zip
Ill-scoped reference checking in TreeCheckers
Find trees which have an info referring to an out-of-scope type parameter or local symbol, as could happen in the test for SI-6981, in which tree transplanting did not substitute symbols in symbol infos. The enclosed, pending test for that bug that will now fail under -Ycheck:extmethods -Xfatal-warnings. [Now checking: extmethods] [check: extmethods] The symbol, tpe or info of tree `(@scala.annotation.tailrec def loop(x: A): Unit = loop(x)) : (x: A)Unit` refers to a out-of-scope symbol, type A in class Foo. tree.symbol.ownerChain: method loop, method bippy$extension, object Foo, object O, package <empty>, package <root> [check: extmethods] The symbol, tpe or info of tree `(val x: A = _) : A` refers to a out-of-scope symbol, type A in class Foo. tree.symbol.ownerChain: value x, method loop, method bippy$extension, object Foo, object O, package <empty>, package <root> [check: extmethods] The symbol, tpe or info of tree `(loop(x)) : (x: A)Unit` refers to a out-of-scope symbol, type A in class Foo. tree.symbol.ownerChain: method loop, method bippy$extension, object Foo, object O, package <empty>, package <root> [check: extmethods] The symbol, tpe or info of tree `(loop) : (x: A)Unit` refers to a out-of-scope symbol, type A in class Foo. tree.symbol.ownerChain: method loop, method bippy$extension, object Foo, object O, package <empty>, package <root> [check: extmethods] The symbol, tpe or info of tree `(x) : A` refers to a out-of-scope symbol, type A in class Foo. tree.symbol.ownerChain: value x, method loop, method bippy$extension, object Foo, object O, package <empty>, package <root> [check: extmethods] The symbol, tpe or info of tree `(<synthetic> val x2: O.Foo[A] = (x1.asInstanceOf[O.Foo[A]]: O.Foo[A])) : O.Foo[A]` refers to a out-of-scope symbol, type A in class Foo. tree.symbol.ownerChain: value x2, method equals$extension, object Foo, object O, package <empty>, package <root> [check: extmethods] The symbol, tpe or info of tree `(<synthetic> val Foo$1: O.Foo[A] = x$1.asInstanceOf[O.Foo[A]]) : O.Foo[A]` refers to a out-of-scope symbol, type A in class Foo. tree.symbol.ownerChain: value Foo$1, method equals$extension, object Foo, object O, package <empty>, package <root> [check: extmethods] The symbol, tpe or info of tree `(Foo$1) : O.Foo[A]` refers to a out-of-scope symbol, type A in class Foo. tree.symbol.ownerChain: value Foo$1, method equals$extension, object Foo, object O, package <empty>, package <root> error: TreeCheckers detected non-compliant trees in t6891.scala one error found
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala2
-rw-r--r--src/reflect/scala/reflect/internal/Trees.scala9
2 files changed, 11 insertions, 0 deletions
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index a4287fb181..c274a9e3af 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -1651,6 +1651,8 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
@inline final def map(f: Symbol => Symbol): Symbol = if (this eq NoSymbol) this else f(this)
+ final def toOption: Option[Symbol] = if (exists) Some(this) else None
+
// ------ cloneing -------------------------------------------------------------------
/** A clone of this symbol. */
diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala
index 431afd286d..62998ef6cb 100644
--- a/src/reflect/scala/reflect/internal/Trees.scala
+++ b/src/reflect/scala/reflect/internal/Trees.scala
@@ -1488,6 +1488,15 @@ trait Trees extends api.Trees { self: SymbolTable =>
}
}
+ trait TreeStackTraverser extends Traverser {
+ import collection.mutable
+ val path: mutable.Stack[Tree] = mutable.Stack()
+ abstract override def traverse(t: Tree) = {
+ path push t
+ try super.traverse(t) finally path.pop()
+ }
+ }
+
private lazy val duplicator = new Transformer {
override val treeCopy = newStrictTreeCopier
override def transform(t: Tree) = {