Skip to content

Commit 1e1725e

Browse files
committed
Fix multiple parsing errors on e.g. try 1
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.
1 parent eed27f4 commit 1e1725e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/dotty/tools/dotc/repl/CompilingInterpreter.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,10 @@ class CompilingInterpreter(
212212
case None => Interpreter.Incomplete
213213
case Some(Nil) => Interpreter.Error // parse error or empty input
214214
case Some(tree :: Nil) if tree.isTerm && !tree.isInstanceOf[Assign] =>
215+
previousOutput.clear() // clear previous error reporting
215216
interpret(s"val $newVarName =\n$line")
216217
case Some(trees) =>
218+
previousOutput.clear() // clear previous error reporting
217219
val req = new Request(line, newLineName)
218220
if (!req.compile())
219221
Interpreter.Error // an error happened during compilation, e.g. a type error
@@ -314,9 +316,13 @@ class CompilingInterpreter(
314316

315317
/** One line of code submitted by the user for interpretation */
316318
private class Request(val line: String, val lineName: String)(implicit ctx: Context) {
317-
private val trees = parse(line) match {
318-
case Some(ts) => ts
319-
case None => Nil
319+
private val trees = {
320+
val parsed = parse(line)
321+
previousOutput.clear() // clear previous error reporting
322+
parsed match {
323+
case Some(ts) => ts
324+
case None => Nil
325+
}
320326
}
321327

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

0 commit comments

Comments
 (0)