Skip to content

Commit

Permalink
Fix multiple parsing errors on e.g. try 1
Browse files Browse the repository at this point in the history
The `CompilingInterpreter` will on a single compile run, make multiple
parsings of the given line(s). This results in multiple warnings from
the parser. As such, clear the warnings until the actual compile is
performed.
  • Loading branch information
felixmulder committed Oct 10, 2016
1 parent 6b12f65 commit 153c566
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/dotty/tools/dotc/repl/CompilingInterpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ class CompilingInterpreter(
case None => Interpreter.Incomplete
case Some(Nil) => Interpreter.Error // parse error or empty input
case Some(tree :: Nil) if tree.isTerm && !tree.isInstanceOf[Assign] =>
previousOutput.clear() // clear previous error reporting
interpret(s"val $newVarName =\n$line")
case Some(trees) =>
previousOutput.clear() // clear previous error reporting
val req = new Request(line, newLineName)
if (!req.compile())
Interpreter.Error // an error happened during compilation, e.g. a type error
Expand Down Expand Up @@ -314,9 +316,13 @@ class CompilingInterpreter(

/** One line of code submitted by the user for interpretation */
private class Request(val line: String, val lineName: String)(implicit ctx: Context) {
private val trees = parse(line) match {
case Some(ts) => ts
case None => Nil
private val trees = {
val parsed = parse(line)
previousOutput.clear() // clear previous error reporting
parsed match {
case Some(ts) => ts
case None => Nil
}
}

/** name to use for the object that will compute "line" */
Expand Down

0 comments on commit 153c566

Please sign in to comment.