Skip to content

Commit d84dab5

Browse files
dwijnandSethTisue
authored andcommitted
REPL: emit parse warnings by reusing the reporter
The original report requires the -deprecation and -source:future flags, for which there is seems to be no support in repl.ScriptedTests. So switched to a non-deprecation syntax warning, that isn't guarded by -source. I might come back and add "pragma" support to the REPL scripts so I can move the test out of pending. Co-authored-by: Seth Tisue <[email protected]>
1 parent 538192a commit d84dab5

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

compiler/src/dotty/tools/repl/ParseResult.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import dotc.core.Contexts._
77
import dotc.core.StdNames.str
88
import dotc.parsing.Parsers.Parser
99
import dotc.parsing.Tokens
10-
import dotc.reporting.Diagnostic
10+
import dotc.reporting.{Diagnostic, StoreReporter}
1111
import dotc.util.SourceFile
1212

1313
import scala.annotation.internal.sharable
@@ -16,7 +16,7 @@ import scala.annotation.internal.sharable
1616
sealed trait ParseResult
1717

1818
/** An error free parsing resulting in a list of untyped trees */
19-
case class Parsed(source: SourceFile, trees: List[untpd.Tree]) extends ParseResult
19+
case class Parsed(source: SourceFile, trees: List[untpd.Tree], reporter: StoreReporter) extends ParseResult
2020

2121
/** A parsing result containing syntax `errors` */
2222
case class SyntaxErrors(sourceCode: String,
@@ -154,7 +154,7 @@ object ParseResult {
154154
reporter.removeBufferedMessages,
155155
stats)
156156
else
157-
Parsed(source, stats)
157+
Parsed(source, stats, reporter)
158158
}
159159
}
160160
}

compiler/src/dotty/tools/repl/ReplCompiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class ReplCompiler extends Compiler {
237237
}
238238

239239
ParseResult(sourceFile)(state) match {
240-
case Parsed(_, trees) =>
240+
case Parsed(_, trees, _) =>
241241
wrap(trees).result
242242
case SyntaxErrors(_, reported, trees) =>
243243
if (errorsAllowed) wrap(trees).result

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import dotty.tools.dotc.core.StdNames._
1818
import dotty.tools.dotc.core.Symbols.{Symbol, defn}
1919
import dotty.tools.dotc.interactive.Completion
2020
import dotty.tools.dotc.printing.SyntaxHighlighting
21-
import dotty.tools.dotc.reporting.MessageRendering
21+
import dotty.tools.dotc.reporting.{MessageRendering, StoreReporter}
2222
import dotty.tools.dotc.reporting.{Message, Diagnostic}
2323
import dotty.tools.dotc.util.Spans.Span
2424
import dotty.tools.dotc.util.{SourceFile, SourcePosition}
@@ -174,8 +174,8 @@ class ReplDriver(settings: Array[String],
174174
}
175175
}
176176

177-
private def newRun(state: State) = {
178-
val run = compiler.newRun(rootCtx.fresh.setReporter(newStoreReporter), state)
177+
private def newRun(state: State, reporter: StoreReporter = newStoreReporter) = {
178+
val run = compiler.newRun(rootCtx.fresh.setReporter(reporter), state)
179179
state.copy(context = run.runContext)
180180
}
181181

@@ -243,7 +243,7 @@ class ReplDriver(settings: Array[String],
243243
unfusedPhases(using ctx).collectFirst { case phase: CollectTopLevelImports => phase.imports }.get
244244

245245
implicit val state = {
246-
val state0 = newRun(istate)
246+
val state0 = newRun(istate, parsed.reporter)
247247
state0.copy(context = state0.context.withSource(parsed.source))
248248
}
249249
compiler
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// scalac: -source:future -deprecation
2+
scala> type M[X] = X match { case Int => String case _ => Int }
3+
-- Deprecation Warning:
4+
1 | type M[X] = X match { case Int => String case _ => Int }
5+
| ^
6+
| `_` is deprecated for wildcard arguments of types: use `?` instead
7+
scala> type N[X] = X match { case List[_] => Int }
8+
-- Deprecation Warning:
9+
1 | type N[X] = X match { case List[_] => Int }
10+
| ^
11+
| `_` is deprecated for wildcard arguments of types: use `?` instead
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
scala> try 1
2+
-- Warning:
3+
1 | try 1
4+
| ^^^^^
5+
| A try without catch or finally is equivalent to putting
6+
| its body in a block; no exceptions are handled.
7+
val res0: Int = 1

compiler/test/dotty/tools/repl/ReplCompilerTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class ReplCompilerTests extends ReplTest {
9595
"""|sealed trait T1
9696
|case class X() extends T1
9797
|case class Y() extends T1
98-
| case object O extends T1
98+
|case object O extends T1
9999
""".stripMargin
100100
}
101101

0 commit comments

Comments
 (0)