summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McDirmid <sean.mcdirmid@gmail.com>2007-09-27 08:40:24 +0000
committerSean McDirmid <sean.mcdirmid@gmail.com>2007-09-27 08:40:24 +0000
commit648556baef4b6f7f1a87f0bf0097bddcdb869cfc (patch)
tree3372d20b6225e27af0950eba89b67d5aecaa21ea
parent67717605c87e854e576489f66cfc150f5eb785f0 (diff)
downloadscala-648556baef4b6f7f1a87f0bf0097bddcdb869cfc.tar.gz
scala-648556baef4b6f7f1a87f0bf0097bddcdb869cfc.tar.bz2
scala-648556baef4b6f7f1a87f0bf0097bddcdb869cfc.zip
Fixed interpreter error recovery mode and somet...
Fixed interpreter error recovery mode and something in Namers that was unlinking module symbols (removed unlink, hope resident compiler is ok, but there are no tests for this in the test suite, better to fix the tests we do have then worry about tests we don't right?)
-rw-r--r--src/compiler/scala/tools/nsc/CompilationUnits.scala5
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala20
-rw-r--r--src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala5
-rw-r--r--src/compiler/scala/tools/nsc/reporters/Reporter.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala6
-rw-r--r--test/files/neg/bug432.check2
-rw-r--r--test/files/run/interpreter.check4
7 files changed, 25 insertions, 21 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilationUnits.scala b/src/compiler/scala/tools/nsc/CompilationUnits.scala
index d0d66afb57..c7d4f84b45 100644
--- a/src/compiler/scala/tools/nsc/CompilationUnits.scala
+++ b/src/compiler/scala/tools/nsc/CompilationUnits.scala
@@ -61,8 +61,11 @@ trait CompilationUnits { self: Global =>
def incompleteInputError(pos: Position, msg:String) =
if (inIDE || !(errorPositions contains pos)) {
+ val hadErrors = !errorPositions.isEmpty
+ if (!hadErrors)
+ reporter.incompleteInputError((pos), msg)
+ else reporter.error((pos), msg)
if (!inIDE) errorPositions += pos
- reporter.incompleteInputError((pos), msg)
}
override def toString() = source.toString()
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index b958024b9e..7805fa32da 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -350,24 +350,19 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
var justNeedsMore = false
reporter.withIncompleteHandler((pos,msg) => {justNeedsMore = true}) {
// simple parse: just parse it, nothing else
- def simpleParse(code: String): List[Tree] = {
- //Console.println("CODE<<" + code + ">>")
+ def simpleParse(code: String): (List[Tree]) = {
+ reporter.reset
val unit =
new CompilationUnit(
new BatchSourceFile("<console>", code.toCharArray()))
val scanner = new compiler.syntaxAnalyzer.UnitParser(unit);
val xxx = scanner.templateStatSeq;
- xxx._2
+ (xxx._2)
}
-
- // parse the main code along with the imports
- reporter.reset
-
- val trees= simpleParse(line)
-
- if (justNeedsMore)
+ val (trees) = simpleParse(line)
+ if (justNeedsMore) {
None
- else if (reporter.hasErrors)
+ } else if (reporter.hasErrors)
Some(Nil) // the result did not parse, so stop
else
Some(trees)
@@ -442,7 +437,8 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
// parse
val trees = parse(line) match {
case None => return IR.Incomplete
- case Some(Nil) => return IR.Error // parse error or empty input
+ case (Some(Nil)) => return IR.Error // parse error or empty input
+ case _ if reporter.hasErrors => return IR.Error
case Some(trees) => trees
}
diff --git a/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala b/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala
index 7ec8b688e7..b2732df204 100644
--- a/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala
@@ -16,6 +16,11 @@ import nsc.Settings
abstract class AbstractReporter extends Reporter {
private val positions = new HashSet[Position]()
+ override def reset = {
+ super.reset
+ positions.clear
+ }
+
val settings: Settings
def display(pos: Position, msg: String, severity: Severity): Unit
diff --git a/src/compiler/scala/tools/nsc/reporters/Reporter.scala b/src/compiler/scala/tools/nsc/reporters/Reporter.scala
index 6eb4401c49..3b1f42b86d 100644
--- a/src/compiler/scala/tools/nsc/reporters/Reporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/Reporter.scala
@@ -46,9 +46,11 @@ abstract class Reporter {
def error(pos: Position, msg: String ): Unit = info0(pos, msg, ERROR, false)
/** An error that could possibly be fixed if the unit were longer.
- * This is used, for example, when the interpreter tries
+ * This is used only when the interpreter tries
* to distinguish fatal errors from those that are due to
* needing more lines of input from the user.
+ *
+ * Should be re-factored into a subclass.
*/
var incompleteInputError: (Position, String) => Unit = error
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index de832671f8..9c30f08d0b 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -160,8 +160,6 @@ trait Namers { self: Analyzer =>
def enterClassSymbol(tree : ClassDef): Symbol = {
var c: Symbol = context.scope.lookup(tree.name);
- // Never take the first path in the IDE because we could be completing c.owner's type!
- // the other path will handle symbol re-use well enough.
if (!inIDE && c.isType && context.scope == c.owner.info.decls && !currentRun.compiles(c)) {
updatePosFlags(c, tree.pos, tree.mods.flags)
setPrivateWithin(tree, c, tree.mods)
@@ -196,8 +194,8 @@ trait Namers { self: Analyzer =>
updatePosFlags(m, tree.pos, tree.mods.flags|MODULE|FINAL)
setPrivateWithin(tree, m, tree.mods)
} else {
- if (m.isTerm && !m.isPackage && currentRun.compiles(m) && (context.scope == m.owner.info.decls))
- context.scope.unlink(m)
+ //if (m.isTerm && !m.isPackage && currentRun.compiles(m) && (context.scope == m.owner.info.decls))
+ // context.scope.unlink(m)
m = context.owner.newModule(tree.pos, tree.name)
m.setFlag(tree.mods.flags)
diff --git a/test/files/neg/bug432.check b/test/files/neg/bug432.check
index 54d4bd7817..f6bc664485 100644
--- a/test/files/neg/bug432.check
+++ b/test/files/neg/bug432.check
@@ -1,4 +1,4 @@
bug432.scala:2: error: Tata is already defined as case class Tata
object Tata
-^
+ ^
one error found
diff --git a/test/files/run/interpreter.check b/test/files/run/interpreter.check
index 0ce5aca0d8..1778b51a87 100644
--- a/test/files/run/interpreter.check
+++ b/test/files/run/interpreter.check
@@ -139,14 +139,14 @@ def x => y => z
^
<console>:1: error: illegal start of simple expression
def x => y => z
- ^
+ ^
scala> <console>:1: error: identifier expected but integer literal found.
[1,2,3]
^
<console>:1: error: ']' expected but eof found.
[1,2,3]
- ^
+ ^
scala>
scala>