diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-08-07 05:20:16 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-08-07 05:20:16 -0700 |
commit | 86c159a7fcd2136b0c05ee0a40e51bceb085b03b (patch) | |
tree | a9de3696d469888751b79b7aa6376c0682c868dc /src | |
parent | cd5153503da73c45c12cbac5e70aad9f90d8cd5c (diff) | |
parent | fd3601a833baac6258d28687d1a73979f4369826 (diff) | |
download | scala-86c159a7fcd2136b0c05ee0a40e51bceb085b03b.tar.gz scala-86c159a7fcd2136b0c05ee0a40e51bceb085b03b.tar.bz2 scala-86c159a7fcd2136b0c05ee0a40e51bceb085b03b.zip |
Merge pull request #1070 from paulp/topic/critical-2.10.x
SI-6063, SI-4945 and restore :warnings in the REPL
Diffstat (limited to 'src')
8 files changed, 76 insertions, 71 deletions
diff --git a/src/compiler/scala/reflect/macros/runtime/Settings.scala b/src/compiler/scala/reflect/macros/runtime/Settings.scala index b7dba665fa..9c24273cd7 100644 --- a/src/compiler/scala/reflect/macros/runtime/Settings.scala +++ b/src/compiler/scala/reflect/macros/runtime/Settings.scala @@ -5,9 +5,9 @@ trait Settings { self: Context => def settings: List[String] = { - val optionName = universe.settings.XmacroSettings.name - val settings = compilerSettings.find(opt => opt.startsWith(optionName)).map(opt => opt.substring(optionName.length + 1)).getOrElse("") - settings.split(",").toList + val us = universe.settings + import us._ + userSetSettings collectFirst { case x: MultiStringSetting if x.name == XmacroSettings.name => x.value } getOrElse Nil } def compilerSettings: List[String] = universe.settings.recreateArgs @@ -33,4 +33,4 @@ trait Settings { try op finally setCompilerSettings(old) } -}
\ No newline at end of file +} diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala index cc1139f8a7..f1c3e80b83 100644 --- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala +++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala @@ -58,6 +58,10 @@ class MainGenericRunner { def isI = !settings.loadfiles.isDefault def dashi = settings.loadfiles.value + // Deadlocks on startup under -i unless we disable async. + if (isI) + settings.Yreplsync.value = true + def combinedCode = { val files = if (isI) dashi map (file => File(file).slurp()) else Nil val str = if (isE) List(dashe) else Nil diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala index 7627edb79d..13ea2d3c24 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala @@ -1173,6 +1173,8 @@ abstract class GenASM extends SubComponent with BytecodeWriters { debuglog("No forwarder for '%s' from %s to '%s'".format(m, jclassName, moduleClass)) else if (conflictingNames(m.name)) log("No forwarder for " + m + " due to conflict with " + linkedClass.info.member(m.name)) + else if (m.hasAccessBoundary) + log(s"No forwarder for non-public member $m") else { log("Adding static forwarder for '%s' from %s to '%s'".format(m, jclassName, moduleClass)) if (m.isAccessor && m.accessed.hasStaticAnnotation) { diff --git a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala index b567293a3f..0e1658ff17 100644 --- a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala +++ b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala @@ -438,7 +438,10 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) } private def warningsCommand(): Result = { - intp.lastWarnings foreach { case (pos, msg) => intp.reporter.warning(pos, msg) } + if (intp.lastWarnings.isEmpty) + "Can't find any cached warnings." + else + intp.lastWarnings foreach { case (pos, msg) => intp.reporter.warning(pos, msg) } } private def javapCommand(line: String): Result = { diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala index 7bdbff8627..e6a142934d 100644 --- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala +++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala @@ -108,27 +108,19 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends else new PathResolver(settings).result.asURLs // the compiler's classpath ) def settings = currentSettings - def savingSettings[T](fn: Settings => Unit)(body: => T): T = { - val saved = currentSettings - currentSettings = saved.copy() - fn(currentSettings) - try body - finally currentSettings = saved - } def mostRecentLine = prevRequestList match { case Nil => "" case req :: _ => req.originalLine } - def rerunWith(names: String*) = { - savingSettings((ss: Settings) => { - import ss._ - names flatMap lookupSetting foreach { - case s: BooleanSetting => s.value = true - case _ => () - } - })(interpret(mostRecentLine)) + // Run the code body with the given boolean settings flipped to true. + def withoutWarnings[T](body: => T): T = beQuietDuring { + val saved = settings.nowarn.value + if (!saved) + settings.nowarn.value = true + + try body + finally if (!saved) settings.nowarn.value = false } - def rerunForWarnings = rerunWith("-deprecation", "-unchecked", "-Xlint") /** construct an interpreter that reports to Console */ def this(settings: Settings) = this(settings, new NewLinePrintWriter(new ConsoleWriter, true)) @@ -699,6 +691,10 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends class ReadEvalPrint(lineId: Int) { def this() = this(freshLineId()) + private var lastRun: Run = _ + private var evalCaught: Option[Throwable] = None + private var conditionalWarnings: List[ConditionalWarning] = Nil + val packageName = sessionNames.line + lineId val readName = sessionNames.read val evalName = sessionNames.eval @@ -754,7 +750,6 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends catch { case ex: Throwable => evalError(path, unwrap(ex)) } } - var evalCaught: Option[Throwable] = None lazy val evalClass = load(evalPath) lazy val evalValue = callEither(resultName) match { case Left(ex) => evalCaught = Some(ex) ; None @@ -776,27 +771,25 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends /** We get a bunch of repeated warnings for reasons I haven't * entirely figured out yet. For now, squash. */ - private def removeDupWarnings(xs: List[(Position, String)]): List[(Position, String)] = { - if (xs.isEmpty) - return Nil - - val ((pos, msg)) :: rest = xs - val filtered = rest filter { case (pos0, msg0) => - (msg != msg0) || (pos.lineContent.trim != pos0.lineContent.trim) || { - // same messages and same line content after whitespace removal - // but we want to let through multiple warnings on the same line - // from the same run. The untrimmed line will be the same since - // there's no whitespace indenting blowing it. - (pos.lineContent == pos0.lineContent) - } + private def updateRecentWarnings(run: Run) { + def loop(xs: List[(Position, String)]): List[(Position, String)] = xs match { + case Nil => Nil + case ((pos, msg)) :: rest => + val filtered = rest filter { case (pos0, msg0) => + (msg != msg0) || (pos.lineContent.trim != pos0.lineContent.trim) || { + // same messages and same line content after whitespace removal + // but we want to let through multiple warnings on the same line + // from the same run. The untrimmed line will be the same since + // there's no whitespace indenting blowing it. + (pos.lineContent == pos0.lineContent) + } + } + ((pos, msg)) :: loop(filtered) } - ((pos, msg)) :: removeDupWarnings(filtered) + val warnings = loop(run.allConditionalWarnings flatMap (_.warnings)) + if (warnings.nonEmpty) + mostRecentWarnings = warnings } - def lastWarnings: List[(Position, String)] = ( - if (lastRun == null) Nil - else removeDupWarnings(lastRun.allConditionalWarnings flatMap (_.warnings)) - ) - private var lastRun: Run = _ private def evalMethod(name: String) = evalClass.getMethods filter (_.getName == name) match { case Array(method) => method case xs => sys.error("Internal error: eval object " + evalClass + ", " + xs.mkString("\n", "\n", "")) @@ -804,6 +797,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends private def compileAndSaveRun(label: String, code: String) = { showCodeIfDebugging(code) val (success, run) = compileSourcesKeepingRun(new BatchSourceFile(label, packaged(code))) + updateRecentWarnings(run) lastRun = run success } @@ -953,11 +947,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends } // compile the result-extraction object - beQuietDuring { - savingSettings(_.nowarn.value = true) { - lineRep compile ResultObjectSourceCode(handlers) - } - } + withoutWarnings(lineRep compile ResultObjectSourceCode(handlers)) } } @@ -1008,12 +998,8 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends case _ => naming.mostRecentVar }) - def lastWarnings: List[(global.Position, String)] = ( - prevRequests.reverseIterator - map (_.lineRep.lastWarnings) - find (_.nonEmpty) - getOrElse Nil - ) + private var mostRecentWarnings: List[(global.Position, String)] = Nil + def lastWarnings = mostRecentWarnings def treesForRequestId(id: Int): List[Tree] = requestForReqId(id).toList flatMap (_.trees) diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala index fc833e2c26..7f627f7904 100644 --- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala @@ -68,7 +68,7 @@ class MutableSettings(val errorFn: String => Unit) if (isOpt) { val newArgs = parseParams(args) if (args eq newArgs) { - errorFn("bad option: '" + x + "'") + errorFn(s"bad option: '$x'") (false, args) } // discard empties, sometimes they appear because of ant or etc. @@ -536,7 +536,7 @@ class MutableSettings(val errorFn: String => Unit) } override def tryToSetColon(args: List[String]) = tryToSet(args) override def tryToSetFromPropertyValue(s: String) = tryToSet(s.trim.split(',').toList) - def unparse: List[String] = value map { name + ":" + _ } + def unparse: List[String] = name :: value withHelpSyntax(name + ":<" + arg + ">") } diff --git a/src/reflect/scala/reflect/internal/settings/MutableSettings.scala b/src/reflect/scala/reflect/internal/settings/MutableSettings.scala index e9899f690d..96fd50646f 100644 --- a/src/reflect/scala/reflect/internal/settings/MutableSettings.scala +++ b/src/reflect/scala/reflect/internal/settings/MutableSettings.scala @@ -14,6 +14,7 @@ abstract class MutableSettings extends AbsSettings { type Setting <: SettingValue type BooleanSetting <: Setting { type T = Boolean } type IntSetting <: Setting { type T = Int } + type MultiStringSetting <: Setting { type T = List[String] } // basically this is a value which remembers if it's been modified trait SettingValue extends AbsSettingValue { @@ -46,4 +47,4 @@ abstract class MutableSettings extends AbsSettings { def XoldPatmat: BooleanSetting def XnoPatmatAnalysis: BooleanSetting def XfullLubs: BooleanSetting -}
\ No newline at end of file +} diff --git a/src/reflect/scala/reflect/runtime/Settings.scala b/src/reflect/scala/reflect/runtime/Settings.scala index eedb88320b..da4f4fbda1 100644 --- a/src/reflect/scala/reflect/runtime/Settings.scala +++ b/src/reflect/scala/reflect/runtime/Settings.scala @@ -1,11 +1,13 @@ package scala.reflect package runtime +import scala.reflect.internal.settings.MutableSettings + /** The Settings class for runtime reflection. * This should be refined, so that settings are settable via command * line options or properties. */ -class Settings extends internal.settings.MutableSettings { +class Settings extends MutableSettings { trait Setting extends SettingValue { } @@ -21,20 +23,27 @@ class Settings extends internal.settings.MutableSettings { override def value: Int = v } - val overrideObjects = new BooleanSetting(false) - val debug = new BooleanSetting(false) - val Ynotnull = new BooleanSetting(false) - val explaintypes = new BooleanSetting(false) - val verbose = new BooleanSetting(false) - val uniqid = new BooleanSetting(false) - val Yshowsymkinds = new BooleanSetting(false) - val Xprintpos = new BooleanSetting(false) - val printtypes = new BooleanSetting(false) - val Yrecursion = new IntSetting(0) - val maxClassfileName = new IntSetting(255) - val Xexperimental = new BooleanSetting(false) - val deepCloning = new BooleanSetting (false) - val XoldPatmat = new BooleanSetting(false) + class MultiStringSetting(xs: List[String]) extends Setting { + type T = List[String] + protected var v: List[String] = xs + override def value: List[String] = v + } + + val Xexperimental = new BooleanSetting(false) + val XfullLubs = new BooleanSetting(false) val XnoPatmatAnalysis = new BooleanSetting(false) - val XfullLubs = new BooleanSetting(false) + val XoldPatmat = new BooleanSetting(false) + val Xprintpos = new BooleanSetting(false) + val Ynotnull = new BooleanSetting(false) + val Yshowsymkinds = new BooleanSetting(false) + val debug = new BooleanSetting(false) + val deepCloning = new BooleanSetting(false) + val explaintypes = new BooleanSetting(false) + val overrideObjects = new BooleanSetting(false) + val printtypes = new BooleanSetting(false) + val uniqid = new BooleanSetting(false) + val verbose = new BooleanSetting(false) + + val Yrecursion = new IntSetting(0) + val maxClassfileName = new IntSetting(255) } |