Skip to content

Revise duplicate diagnostics logic #14845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ abstract class Reporter extends interfaces.ReporterResult {
case w: Warning if ctx.settings.XfatalWarnings.value => w.toError
case _ => dia
if !isHidden(d) then // avoid isHidden test for summarized warnings so that message is not forced
markReported(d)
withMode(Mode.Printing)(doReport(d))
d match {
case _: Warning => _warningCount += 1
Expand Down Expand Up @@ -236,6 +237,8 @@ abstract class Reporter extends interfaces.ReporterResult {
def isHidden(dia: Diagnostic)(using Context): Boolean =
ctx.mode.is(Mode.Printing)

def markReported(dia: Diagnostic)(using Context): Unit = ()

/** Does this reporter contain errors that have yet to be reported by its outer reporter ?
* Note: this is always false when there is no outer reporter.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,27 @@ trait UniqueMessagePositions extends Reporter {

private val positions = new mutable.HashMap[(SourceFile, Integer), Diagnostic]

extension (dia1: Diagnostic)
private def hides(dia2: Diagnostic)(using Context): Boolean =
if dia2.msg.showAlways then dia1.msg.getClass == dia2.msg.getClass
else dia1.level >= dia2.level

/** Logs a position and returns true if it was already logged.
* @note Two positions are considered identical for logging if they have the same point.
*/
override def isHidden(dia: Diagnostic)(using Context): Boolean =
extension (dia1: Diagnostic) def hides(dia2: Diagnostic): Boolean =
if dia2.msg.showAlways then dia1.msg.getClass == dia2.msg.getClass
else dia1.level >= dia2.level
super.isHidden(dia) || {
super.isHidden(dia)
||
dia.pos.exists
&& !ctx.settings.YshowSuppressedErrors.value
&& {
var shouldHide = false
for (pos <- dia.pos.start to dia.pos.end)
positions get (ctx.source, pos) match {
case Some(dia1) if dia1.hides(dia) => shouldHide = true
case _ => positions((ctx.source, pos)) = dia
}
shouldHide
}
}
&& (dia.pos.start to dia.pos.end).exists(pos =>
positions.get((ctx.source, pos)).exists(_.hides(dia)))

override def markReported(dia: Diagnostic)(using Context): Unit =
if dia.pos.exists then
for (pos <- dia.pos.start to dia.pos.end)
positions.get(ctx.source, pos) match
case Some(dia1) if dia1.hides(dia) =>
case _ => positions((ctx.source, pos)) = dia
super.markReported(dia)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object Test {
type T
type R

summon[TupledFunction[(erased T) => R, erased Tuple1[T] => R]] // error
summon[TupledFunction[(erased T) => R, erased Tuple1[T] => R]] // error // error
summon[TupledFunction[(erased T, T) => R, (erased (T, T)) => R]] // error
summon[TupledFunction[(erased T, T, T) => R,(erased (T, T, T)) => R]] // error
summon[TupledFunction[(erased T, T, T, T) => R,(erased (T, T, T, T)) => R]] // error
Expand Down
3 changes: 3 additions & 0 deletions tests/neg/i12457.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import language.`3.1-migration`

trait X [ X <: Z , Z >: X [ R ] ] // error
2 changes: 2 additions & 0 deletions tests/neg/i14834.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type F[_] = A
type A = F[?] // error: cyclic
2 changes: 1 addition & 1 deletion tests/neg/i6056.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ object i0{
import i0.i0 // error
def i0={
import _ // error
import
import // error
} // error
}
2 changes: 1 addition & 1 deletion tests/neg/i7818.scala
Original file line number Diff line number Diff line change
@@ -1 +1 @@
def foo = (x: @) => () // error
def foo = (x: @) => () // error // error
2 changes: 1 addition & 1 deletion tests/neg/i9328.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Foo2[T <: Id[T]] // error // error

object Foo { // error
object Foo { }
Foo { }
Foo { } // error
}
implicit class Foo(a: Float) // error
case class Foo()
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/parser-stability-17.scala
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
trait x0[] { x0: x0 => } // error // error
class x0[x1] extends x0[x0 x0] x2 x0 // error // error
class x0[x1] extends x0[x0 x0] x2 x0 // error // error // error
2 changes: 1 addition & 1 deletion tests/neg/parser-stability-9.scala
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import
import // error
// error
8 changes: 7 additions & 1 deletion tests/neg/t5702-neg-bad-and-wild.check
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
|
| longer explanation available when compiling with `-explain`
-- [E032] Syntax Error: tests/neg/t5702-neg-bad-and-wild.scala:23:17 ---------------------------------------------------
23 | val K(ns @ _*, xx) = k // error: pattern expected
23 | val K(ns @ _*, xx) = k // error: pattern expected // error
| ^
| pattern expected
|
Expand All @@ -50,3 +50,9 @@
| Not found: *
|
| longer explanation available when compiling with `-explain`
-- [E045] Cyclic Error: tests/neg/t5702-neg-bad-and-wild.scala:23:19 ---------------------------------------------------
23 | val K(ns @ _*, xx) = k // error: pattern expected // error
| ^
| Recursive value $1$ needs type
|
| longer explanation available when compiling with `-explain`
2 changes: 1 addition & 1 deletion tests/neg/t5702-neg-bad-and-wild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object Test {
// good syntax, bad semantics, detected by typer
//gowild.scala:14: error: star patterns must correspond with varargs parameters
val K(x @ _*) = k
val K(ns @ _*, xx) = k // error: pattern expected
val K(ns @ _*, xx) = k // error: pattern expected // error
val K(x) = k // error: x is already defined as value x
val (b, _ * ) = (5,6) // ok
// no longer complains
Expand Down