summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/internal/SymbolTable.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-08-19 15:12:04 -0700
committerPaul Phillips <paulp@improving.org>2013-08-19 15:12:04 -0700
commitfde88c76ceb1e575b89c813a039df1967c6f995c (patch)
treea9210a6aa2165f69800a7471acc027dd42f01962 /src/reflect/scala/reflect/internal/SymbolTable.scala
parenta124ab7f48dfc1e49b203af7a14904eaa5029577 (diff)
downloadscala-fde88c76ceb1e575b89c813a039df1967c6f995c.tar.gz
scala-fde88c76ceb1e575b89c813a039df1967c6f995c.tar.bz2
scala-fde88c76ceb1e575b89c813a039df1967c6f995c.zip
No longer crash on NoSymbol.owner.
Historically calling NoSymbol.owner has crashed the compiler. With this commit, NoSymbol owns itself. This is consistent with the way ownership chains are handled elsewhere in the compiler (e.g. NoContext.owner is NoContext, NoSymbol.enclClass is NoSymbol, and so on) and frees every call site which handles symbols from having to perform precondition tests against NoSymbol. Since calling NoSymbol.owner sometimes (not always) indicates a bug which we'd like to catch sooner than later, I have introduced a couple more methods for selected call sites. def owner: Symbol // NoSymbol.owner is self, log if -Xdev def safeOwner: Symbol // NoSymbol.owner is self, ignore def assertOwner: Symbol // NoSymbol.owner is fatal The idea is that everyone can call sym.owner without undue anxiety or paranoid null-like tests. When compiling under -Xdev calls to `owner` are logged with a stack trace, so any call sites for which that is an expected occurrence should call safeOwner instead to communicate the intention and stay out of the log. Conversely, any call site where crashing on the owner call was a desirable behavior can opt into calling assertOwner. This commit also includes all the safeOwner calls necessary to give us a silent log when compiling scala.
Diffstat (limited to 'src/reflect/scala/reflect/internal/SymbolTable.scala')
-rw-r--r--src/reflect/scala/reflect/internal/SymbolTable.scala7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/reflect/scala/reflect/internal/SymbolTable.scala b/src/reflect/scala/reflect/internal/SymbolTable.scala
index c340670635..f0be0f7d05 100644
--- a/src/reflect/scala/reflect/internal/SymbolTable.scala
+++ b/src/reflect/scala/reflect/internal/SymbolTable.scala
@@ -60,6 +60,7 @@ abstract class SymbolTable extends macros.Universe
def shouldLogAtThisPhase = false
def isPastTyper = false
+ protected def isDeveloper: Boolean = settings.debug
@deprecated("Give us a reason", "2.10.0")
def abort(): Nothing = abort("unknown error")
@@ -69,8 +70,12 @@ abstract class SymbolTable extends macros.Universe
/** Override with final implementation for inlining. */
def debuglog(msg: => String): Unit = if (settings.debug) log(msg)
- def devWarning(msg: => String): Unit = if (settings.debug) Console.err.println(msg)
+ def devWarning(msg: => String): Unit = if (isDeveloper) Console.err.println(msg)
def throwableAsString(t: Throwable): String = "" + t
+ def throwableAsString(t: Throwable, maxFrames: Int): String = t.getStackTrace take maxFrames mkString "\n at "
+
+ @inline final def devWarningDumpStack(msg: => String, maxFrames: Int): Unit =
+ devWarning(msg + "\n" + throwableAsString(new Throwable, maxFrames))
/** Prints a stack trace if -Ydebug or equivalent was given, otherwise does nothing. */
def debugStack(t: Throwable): Unit = devWarning(throwableAsString(t))