Skip to content

Commit

Permalink
Change behavior of Xfatal-warnings & adjust final tests
Browse files Browse the repository at this point in the history
  • Loading branch information
szymon-rd committed Dec 15, 2023
1 parent 78adb39 commit daf1718
Show file tree
Hide file tree
Showing 127 changed files with 1,005 additions and 172 deletions.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
runCtx.withProgressCallback: cb =>
_progress = Progress(cb, this, fusedPhases.map(_.traversals).sum)
runPhases(allPhases = fusedPhases)(using runCtx)
ctx.reporter.finalizeReporting()
if (!ctx.reporter.hasErrors)
Rewrites.writeBack()
suppressions.runFinished(hasErrors = ctx.reporter.hasErrors)
Expand Down
13 changes: 6 additions & 7 deletions compiler/src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,14 @@ abstract class Reporter extends interfaces.ReporterResult {
end issueUnconfigured

def issueIfNotSuppressed(dia: Diagnostic)(using Context): Unit =
def toErrorIfFatal(dia: Diagnostic) = dia match
case w: Warning if ctx.settings.silentWarnings.value => dia
case w: ConditionalWarning if w.isSummarizedConditional => dia
case w: Warning if ctx.settings.XfatalWarnings.value => w.toError
case _ => dia

def go() =
import Action.*
dia match
case w: Warning => WConf.parsed.action(dia) match
case Error => issueUnconfigured(w.toError)
case Warning => issueUnconfigured(toErrorIfFatal(w))
case Verbose => issueUnconfigured(toErrorIfFatal(w.setVerbose()))
case Warning => issueUnconfigured(w)
case Verbose => issueUnconfigured(w.setVerbose())
case Info => issueUnconfigured(w.toInfo)
case Silent =>
case _ => issueUnconfigured(dia)
Expand Down Expand Up @@ -214,6 +209,10 @@ abstract class Reporter extends interfaces.ReporterResult {
def incomplete(dia: Diagnostic)(using Context): Unit =
incompleteHandler(dia, ctx)

def finalizeReporting()(using Context) =
if (hasWarnings && ctx.settings.XfatalWarnings.value)
report(new Error("No warnings can be incurred under -Werror.", NoSourcePosition))

/** Summary of warnings and errors */
def summary: String = {
val b = new mutable.ListBuffer[String]
Expand Down
11 changes: 11 additions & 0 deletions tests/init-global/neg/context-sensitivity.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Warning: tests/init-global/neg/context-sensitivity.scala:9:21 -------------------------------------------------------
9 | def foo(): Int = A.m
| ^^^
| Access uninitialized field value m. Calling trace:
| ├── object A: [ context-sensitivity.scala:14 ]
| │ ^
| ├── val m: Int = box1.value.foo() [ context-sensitivity.scala:17 ]
| │ ^^^^^^^^^^^^^^^^
| └── def foo(): Int = A.m [ context-sensitivity.scala:9 ]
| ^^^
No warnings can be incurred under -Werror.
4 changes: 3 additions & 1 deletion tests/init-global/neg/context-sensitivity.scala
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class C(var x: Int) extends Foo {
}

class D(var y: Int) extends Foo {
def foo(): Int = A.m // error
def foo(): Int = A.m
}

class Box(var value: Foo)
Expand All @@ -15,3 +15,5 @@ object A:
val box1: Box = new Box(new C(5))
val box2: Box = new Box(new D(10))
val m: Int = box1.value.foo()

// nopos-error: No warnings can be incurred under -Werror.
15 changes: 8 additions & 7 deletions tests/init-global/neg/global-cycle1.check
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
-- Error: tests/init-global/neg/global-cycle1.scala:1:7 ----------------------------------------------------------------
1 |object A { // error
-- Warning: tests/init-global/neg/global-cycle1.scala:1:7 --------------------------------------------------------------
1 |object A {
| ^
| Cyclic initialization: object A -> object B -> object A. Calling trace:
| ├── object A { // error [ global-cycle1.scala:1 ]
| ├── object A { [ global-cycle1.scala:1 ]
| │ ^
| ├── val a: Int = B.b [ global-cycle1.scala:2 ]
| │ ^
| ├── object B { [ global-cycle1.scala:5 ]
| │ ^
| └── val b: Int = A.a // error [ global-cycle1.scala:6 ]
| └── val b: Int = A.a [ global-cycle1.scala:6 ]
| ^
-- Error: tests/init-global/neg/global-cycle1.scala:6:17 ---------------------------------------------------------------
6 | val b: Int = A.a // error
-- Warning: tests/init-global/neg/global-cycle1.scala:6:17 -------------------------------------------------------------
6 | val b: Int = A.a
| ^^^
| Access uninitialized field value a. Calling trace:
| ├── object B { [ global-cycle1.scala:5 ]
| │ ^
| └── val b: Int = A.a // error [ global-cycle1.scala:6 ]
| └── val b: Int = A.a [ global-cycle1.scala:6 ]
| ^^^
No warnings can be incurred under -Werror.
6 changes: 4 additions & 2 deletions tests/init-global/neg/global-cycle1.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
object A { // error
object A {
val a: Int = B.b
}

object B {
val b: Int = A.a // error
val b: Int = A.a
}

@main
def Test = print(A.a)

// nopos-error: No warnings can be incurred under -Werror.
21 changes: 21 additions & 0 deletions tests/init-global/neg/global-cycle14.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Warning: tests/init-global/neg/global-cycle14.scala:8:7 -------------------------------------------------------------
8 |object A {
| ^
| Cyclic initialization: object A -> object B -> object A. Calling trace:
| ├── object A { [ global-cycle14.scala:8 ]
| │ ^
| ├── val n: Int = B.m [ global-cycle14.scala:9 ]
| │ ^
| ├── object B { [ global-cycle14.scala:12 ]
| │ ^
| └── val m: Int = A.n [ global-cycle14.scala:13 ]
| ^
-- Warning: tests/init-global/neg/global-cycle14.scala:13:17 -----------------------------------------------------------
13 | val m: Int = A.n
| ^^^
| Access uninitialized field value n. Calling trace:
| ├── object B { [ global-cycle14.scala:12 ]
| │ ^
| └── val m: Int = A.n [ global-cycle14.scala:13 ]
| ^^^
No warnings can be incurred under -Werror.
6 changes: 4 additions & 2 deletions tests/init-global/neg/global-cycle14.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ object O {
val d = Data(3)
}

object A { // error
object A {
val n: Int = B.m
}

object B {
val m: Int = A.n // error
val m: Int = A.n
}

// nopos-error: No warnings can be incurred under -Werror.
11 changes: 11 additions & 0 deletions tests/init-global/neg/global-cycle2.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Warning: tests/init-global/neg/global-cycle2.scala:6:21 -------------------------------------------------------------
6 | def foo(): Int = A.a * 2
| ^^^
| Access uninitialized field value a. Calling trace:
| ├── object A { [ global-cycle2.scala:1 ]
| │ ^
| ├── val a: Int = B.foo() [ global-cycle2.scala:2 ]
| │ ^^^^^^^
| └── def foo(): Int = A.a * 2 [ global-cycle2.scala:6 ]
| ^^^
No warnings can be incurred under -Werror.
4 changes: 3 additions & 1 deletion tests/init-global/neg/global-cycle2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ object A {
}

object B {
def foo(): Int = A.a * 2 // error
def foo(): Int = A.a * 2
}

// nopos-error: No warnings can be incurred under -Werror.
11 changes: 11 additions & 0 deletions tests/init-global/neg/global-cycle3.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Warning: tests/init-global/neg/global-cycle3.scala:2:21 -------------------------------------------------------------
2 | def foo(): Int = B.a + 10
| ^^^
| Access uninitialized field value a. Calling trace:
| ├── object B { [ global-cycle3.scala:5 ]
| │ ^
| ├── val a: Int = A(4).foo() [ global-cycle3.scala:6 ]
| │ ^^^^^^^^^^
| └── def foo(): Int = B.a + 10 [ global-cycle3.scala:2 ]
| ^^^
No warnings can be incurred under -Werror.
4 changes: 3 additions & 1 deletion tests/init-global/neg/global-cycle3.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class A(x: Int) {
def foo(): Int = B.a + 10 // error
def foo(): Int = B.a + 10
}

object B {
val a: Int = A(4).foo()
}

// nopos-error: No warnings can be incurred under -Werror.
11 changes: 11 additions & 0 deletions tests/init-global/neg/global-cycle4.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Warning: tests/init-global/neg/global-cycle4.scala:10:21 ------------------------------------------------------------
10 | def foo(): Int = O.a + 10
| ^^^
| Access uninitialized field value a. Calling trace:
| ├── object O { [ global-cycle4.scala:17 ]
| │ ^
| ├── val a: Int = D(5).bar().foo() [ global-cycle4.scala:18 ]
| │ ^^^^^^^^^^^^^^^^
| └── def foo(): Int = O.a + 10 [ global-cycle4.scala:10 ]
| ^^^
No warnings can be incurred under -Werror.
4 changes: 3 additions & 1 deletion tests/init-global/neg/global-cycle4.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class B extends A {
}

class C extends A {
def foo(): Int = O.a + 10 // error
def foo(): Int = O.a + 10
}

class D(x: Int) {
Expand All @@ -17,3 +17,5 @@ class D(x: Int) {
object O {
val a: Int = D(5).bar().foo()
}

// nopos-error: No warnings can be incurred under -Werror.
10 changes: 10 additions & 0 deletions tests/init-global/neg/global-cycle5.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Warning: tests/init-global/neg/global-cycle5.scala:10:17 ------------------------------------------------------------
10 | val b: Int = A.a.foo()
| ^^^
|Reading mutable state of object A during initialization of object B.
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
|├── object B { [ global-cycle5.scala:9 ]
|│ ^
|└── val b: Int = A.a.foo() [ global-cycle5.scala:10 ]
| ^^^
No warnings can be incurred under -Werror.
5 changes: 3 additions & 2 deletions tests/init-global/neg/global-cycle5.scala
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object A {
}

object B {
val b: Int = A.a.foo() // error
val b: Int = A.a.foo()
}

class Y extends X {
Expand All @@ -20,4 +20,5 @@ object C {

def main = {
A.a = new Y(); C
}
}
// nopos-error: No warnings can be incurred under -Werror.
29 changes: 29 additions & 0 deletions tests/init-global/neg/global-cycle6.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- Warning: tests/init-global/neg/global-cycle6.scala:1:7 --------------------------------------------------------------
1 |object A {
| ^
| Cyclic initialization: object A -> object B -> object A. Calling trace:
| ├── object A { [ global-cycle6.scala:1 ]
| │ ^
| ├── val n: Int = B.m [ global-cycle6.scala:2 ]
| │ ^
| ├── object B { [ global-cycle6.scala:8 ]
| │ ^
| ├── val a = new A.Inner [ global-cycle6.scala:9 ]
| │ ^^^^^^^^^^^
| ├── class Inner { [ global-cycle6.scala:3 ]
| │ ^
| └── println(n) [ global-cycle6.scala:4 ]
| ^
-- Warning: tests/init-global/neg/global-cycle6.scala:4:12 -------------------------------------------------------------
4 | println(n)
| ^
| Access uninitialized field value n. Calling trace:
| ├── object B { [ global-cycle6.scala:8 ]
| │ ^
| ├── val a = new A.Inner [ global-cycle6.scala:9 ]
| │ ^^^^^^^^^^^
| ├── class Inner { [ global-cycle6.scala:3 ]
| │ ^
| └── println(n) [ global-cycle6.scala:4 ]
| ^
No warnings can be incurred under -Werror.
7 changes: 4 additions & 3 deletions tests/init-global/neg/global-cycle6.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object A { // error
object A {
val n: Int = B.m
class Inner {
println(n) // error
println(n)
}
}

Expand All @@ -22,4 +22,5 @@ object O {
val a = new A.Inner
val m: Int = 10
}
}
}
// nopos-error: No warnings can be incurred under -Werror.
21 changes: 21 additions & 0 deletions tests/init-global/neg/global-cycle7.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Warning: tests/init-global/neg/global-cycle7.scala:1:7 --------------------------------------------------------------
1 |object A {
| ^
| Cyclic initialization: object A -> object B -> object A. Calling trace:
| ├── object A { [ global-cycle7.scala:1 ]
| │ ^
| ├── val n: Int = B.m [ global-cycle7.scala:2 ]
| │ ^
| ├── object B { [ global-cycle7.scala:5 ]
| │ ^
| └── val m: Int = A.n [ global-cycle7.scala:6 ]
| ^
-- Warning: tests/init-global/neg/global-cycle7.scala:6:17 -------------------------------------------------------------
6 | val m: Int = A.n
| ^^^
| Access uninitialized field value n. Calling trace:
| ├── object B { [ global-cycle7.scala:5 ]
| │ ^
| └── val m: Int = A.n [ global-cycle7.scala:6 ]
| ^^^
No warnings can be incurred under -Werror.
6 changes: 4 additions & 2 deletions tests/init-global/neg/global-cycle7.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
object A { // error
object A {
val n: Int = B.m
}

object B {
val m: Int = A.n // error
val m: Int = A.n
}

abstract class TokensCommon {
Expand All @@ -16,3 +16,5 @@ object JavaTokens extends TokensCommon {
final def maxToken: Int = DOUBLE
final val DOUBLE = 188
}

// nopos-error: No warnings can be incurred under -Werror.
17 changes: 17 additions & 0 deletions tests/init-global/neg/global-cycle8.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Warning: tests/init-global/neg/global-cycle8.scala:9:7 --------------------------------------------------------------
9 |object O {
| ^
| Cyclic initialization: object O -> object P -> object O. Calling trace:
| ├── object O { [ global-cycle8.scala:9 ]
| │ ^
| ├── println(P.m) [ global-cycle8.scala:11 ]
| │ ^
| ├── object P { [ global-cycle8.scala:14 ]
| │ ^
| ├── val m = Q.bar(new B) [ global-cycle8.scala:15 ]
| │ ^^^^^^^^^^^^
| ├── def bar(b: B) = b.a.foo() [ global-cycle8.scala:19 ]
| │ ^^^^^^^^^
| └── def foo() = println(O.n) [ global-cycle8.scala:2 ]
| ^
No warnings can be incurred under -Werror.
4 changes: 3 additions & 1 deletion tests/init-global/neg/global-cycle8.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class B {
val a = new A
}

object O { // error
object O {
val n: Int = 10
println(P.m)
}
Expand All @@ -18,3 +18,5 @@ object P {
object Q {
def bar(b: B) = b.a.foo()
}

// nopos-error: No warnings can be incurred under -Werror.
10 changes: 10 additions & 0 deletions tests/init-global/neg/global-irrelevance1.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Warning: tests/init-global/neg/global-irrelevance1.scala:5:12 -------------------------------------------------------
5 | var y = A.x * 2
| ^^^
|Reading mutable state of object A during initialization of object B.
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
|├── object B: [ global-irrelevance1.scala:4 ]
|│ ^
|└── var y = A.x * 2 [ global-irrelevance1.scala:5 ]
| ^^^
No warnings can be incurred under -Werror.
3 changes: 2 additions & 1 deletion tests/init-global/neg/global-irrelevance1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ object A:
var x = 6

object B:
var y = A.x * 2 // error
var y = A.x * 2
// nopos-error: No warnings can be incurred under -Werror.
Loading

0 comments on commit daf1718

Please sign in to comment.