Skip to content

Commit 96167e6

Browse files
committed
Report the correct errors in the IDE
In some situations (like when interpolating type variables) the logic changes depending on whether we have unreported errors or not. Before this commit, we assumed that any error in a StoreReporter was unreported, but this is wrong: the IDE, the REPL and other tools use a StoreReporter as their root reporter. This commit fixes this by making sure all the code that looks for unreported errors does so by calling `hasUnreportedErrors` and making that method return false when there is no outer reporter.
1 parent 63180e6 commit 96167e6

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,10 @@ abstract class Reporter extends interfaces.ReporterResult {
238238
def isHidden(m: MessageContainer)(implicit ctx: Context): Boolean =
239239
ctx.mode.is(Mode.Printing)
240240

241-
/** Does this reporter contain not yet reported errors or warnings? */
242-
def hasPendingErrors: Boolean = false
241+
/** Does this reporter contains errors that have yet to be reported by its outer reporter ?
242+
* Note: this is always false when there is no outer reporter.
243+
*/
244+
def hasUnreportedErrors: Boolean = false
243245

244246
/** If this reporter buffers messages, remove and return all buffered messages. */
245247
def removeBufferedMessages(implicit ctx: Context): List[MessageContainer] = Nil

compiler/src/dotty/tools/dotc/reporting/StoreReporter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class StoreReporter(outer: Reporter) extends Reporter {
2828
infos += m
2929
}
3030

31-
override def hasPendingErrors: Boolean =
32-
infos != null && infos.exists(_.isInstanceOf[Error])
31+
override def hasUnreportedErrors: Boolean =
32+
outer != null && infos != null && infos.exists(_.isInstanceOf[Error])
3333

3434
override def removeBufferedMessages(implicit ctx: Context): List[MessageContainer] =
3535
if (infos != null) try infos.toList finally infos = null

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,7 @@ trait Inferencing { this: Typer =>
432432
// found : Int(1)
433433
// required: String
434434
// val y: List[List[String]] = List(List(1))
435-
val hasUnreportedErrors = state.reporter match {
436-
case r: StoreReporter if r.hasErrors => true
437-
case _ => false
438-
}
435+
val hasUnreportedErrors = state.reporter.hasUnreportedErrors
439436
def constraint = state.constraint
440437
for (tvar <- qualifying)
441438
if (!tvar.isInstantiated && state.constraint.contains(tvar)) {

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ object ProtoTypes {
264264
targ = arg.withType(WildcardType)
265265
else {
266266
targ = typerFn(arg)
267-
if (!ctx.reporter.hasPendingErrors) {
267+
if (!ctx.reporter.hasUnreportedErrors) {
268268
// FIXME: This can swallow warnings by updating the typerstate from a nested
269269
// context that gets discarded later. But we do have to update the
270270
// typerstate if there are no errors. If we also omitted the next two lines

language-server/test/dotty/tools/languageserver/DiagnosticsTest.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,14 @@ class DiagnosticsTest {
1515
(m1 to m2, """found: String("foo")
1616
|required: Int""".stripMargin, Error, Some(TypeMismatchID))
1717
)
18+
19+
@Test def diagnosticMissingLambdaBody: Unit =
20+
code"""object Test {
21+
| Nil.map(x => x).filter(x$m1 =>$m2)
22+
|$m3}""".withSource
23+
.diagnostics(m1,
24+
(m2 to m3, "illegal start of simple expression", Error, Some(IllegalStartSimpleExprID)),
25+
(m1 to m1, """found: Null
26+
|required: Boolean""".stripMargin, Error, Some(TypeMismatchID))
27+
)
1828
}

0 commit comments

Comments
 (0)