Skip to content

Commit 853f8ea

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 `Reporter#hasPendingErrors` and changing the implementation of `StoreReporter#hasPendingErrors` to return false when there is no outer reporter.
1 parent 8d99f78 commit 853f8ea

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

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

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

31+
/** Does this reporter contains errors that have yet to be reported by its outer reporter ?
32+
* Note: this is always false when `outer` is null.
33+
*/
3134
override def hasPendingErrors: Boolean =
32-
infos != null && infos.exists(_.isInstanceOf[Error])
35+
outer != null && infos != null && infos.exists(_.isInstanceOf[Error])
3336

3437
override def removeBufferedMessages(implicit ctx: Context): List[MessageContainer] =
3538
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.hasPendingErrors
439436
def constraint = state.constraint
440437
for (tvar <- qualifying)
441438
if (!tvar.isInstantiated && state.constraint.contains(tvar)) {

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)