Skip to content
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

Report all warnings on Werror and fail at the end #18829

Closed
wants to merge 0 commits into from

Conversation

szymon-rd
Copy link
Contributor

@szymon-rd szymon-rd commented Nov 2, 2023

Fix #18634

[test_scala2_library_tasty]

@szymon-rd
Copy link
Contributor Author

still tbd: massive refactor of tests, but I want to hear if anyone has something against this solution

Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to be able to check if a line emitted a warning or not in the neg tests.

One option would be to make the test framework detect the warnings and // warn tags to validate them as we do with // error.

Another option would be to make the test framework interpret fatal warnings as errors.

@@ -2,10 +2,12 @@

class Test {
def remove[S](a: S | Int, f: Int => S):S = a match {
case a: S => a // error
case a: S => a // warn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tag is not checked by the testing framework. This implies that this file in not testing anything. This implies that all tests that do not have a test file are broken.

We need to make sure that we check the position and number of warnings emitted under -Xfatal-warnings/-Werror. Our assumption when designing those tests was that we would check them as errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dale recently added that feature, it should be working (at least it's in Vulpix in ParallelTesting). I will make sure it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Now I see. It won't test both

@nicolasstucki
Copy link
Contributor

One option would be to make the test framework detect the warnings and // warn tags to validate them as we do with // error.

The drawback of this approach is that we might need to add more // warn in tests. This will be a bit more work on our side but would make tests more robust.

@dwijnand
Copy link
Member

dwijnand commented Nov 3, 2023

One option would be to make the test framework detect the warnings and // warn tags to validate them as we do with // error.

Move it to tests/warn/.

@nicolasstucki
Copy link
Contributor

Move it to tests/warn/.

We have tests that check both warnings and errors at the same time.

@szymon-rd
Copy link
Contributor Author

I can move most of them to warn. For the rest, I will maybe just create the output check files.

@szymon-rd
Copy link
Contributor Author

szymon-rd commented Nov 22, 2023

All the tests are passing now. There are a lot of changes, but most are just simple modifications done by scripts.

@szymon-rd
Copy link
Contributor Author

szymon-rd commented Nov 22, 2023

Right now one failing was added, and this branch fails after rebase. But I will fix it after the review, as broken tests keep appearing on main and I will need to fix the ones that will appear before the review is finished.

@nicolasstucki nicolasstucki self-assigned this Nov 27, 2023
@@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
report(new Error("No warnings can be incurred under -Werror.", NoSourcePosition))
report(new Error("Unexpected warnings under -Werror.", NoSourcePosition))

@@ -216,7 +216,10 @@ class CompilationTests {
@Test def checkInitGlobal: Unit = {
implicit val testGroup: TestGroup = TestGroup("checkInitGlobal")
val options = defaultOptions.and("-Ysafe-init-global", "-Xfatal-warnings")
compileFilesInDir("tests/init-global/neg", options).checkExpectedErrors()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
compileFilesInDir("tests/init-global/neg", options).checkExpectedErrors()

This one is repeated. Keep the one with the filter (2 lines bellow).

compileFilesInDir("tests/init-global/neg", options, FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyBlacklisted)).checkExpectedErrors()

@@ -216,7 +216,10 @@ class CompilationTests {
@Test def checkInitGlobal: Unit = {
implicit val testGroup: TestGroup = TestGroup("checkInitGlobal")
val options = defaultOptions.and("-Ysafe-init-global", "-Xfatal-warnings")
compileFilesInDir("tests/init-global/neg", options).checkExpectedErrors()
compileFilesInDir("tests/init-global/pos", options).checkCompile()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
compileFilesInDir("tests/init-global/pos", options).checkCompile()

same duplication

compileFilesInDir("tests/init-global/neg", options, FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyBlacklisted)).checkExpectedErrors()
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global"), FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyBlacklisted)).checkWarnings()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global"), FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyBlacklisted)).checkWarnings()
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global"), FileFilter.exclude(TestSources.warnInitGlobalScala2LibraryTastyBlacklisted)).checkWarnings()

Create the blacklist only if it is necessary. Otherwise remove the filter.

Suggested change
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global"), FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyBlacklisted)).checkWarnings()
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global")).checkWarnings()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will only be tested on lightly or with [test_scala2_library_tasty]. I will add this to your PR.


def f(e: Enum): Enum = e

@main def main(): Unit = println(Enum.b)

// nopos-error: No warnings can be incurred under -Werror.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should probably be moved to tests/init-global/warn/i12544b.scala.

Same for other tests that only have warnings and no errors. We do not need to add checkfiles for these kinds of tests.

@@ -776,7 +776,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
end maybeFailureMessage

def getWarnMapAndExpectedCount(files: Seq[JFile]): (HashMap[String, Integer], Int) =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do not have any // warn or // nopos-warn we should emit an error. Similar to the one for neg test:

https://github.com/lampepfl/dotty/blob/4d45087448d8e649d944b6136ceb406e001983df/compiler/test/dotty/tools/vulpix/ParallelTesting.scala#L893-L893

case TypedRecoveryCompleted =>
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont remove the last \n of the files

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to add the last \n of the file.

@@ -10,7 +10,7 @@ class M(x: Int) {
class L1(x: Int) { val n: Int = 5 }

class A(b: B, x: Int) {
println(d.n)
println(d.n)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
println(d.n)
println(d.n)

class Foo {
val len = name.size
val name: String = "Jack" // warn
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

val '{ $a: Int } = x
val '{ $b: Any } = x
val '{ $c } = x

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simplify the work needed to get this PR considerably if we split it in parts.

  1. Add warn test infrastructure
  2. Migrate neg tests into warn tests (in batches)
  3. Change warning/error behavior

@szymon-rd
Copy link
Contributor Author

Good idea. I will split it in a couple of PRs.

szymon-rd added a commit that referenced this pull request Jan 11, 2024
…Batch 1 (#19242)

Adds functionality to vulpix that allows putting nopos-warns in comments
& First batch of tests moved from tests/neg to tests/warn.
PR 2/5 (merge consecutively, per [Nicolas'
suggestion](#18829 (review))

Split up version of #18829
nicolasstucki added a commit that referenced this pull request Jan 19, 2024
The second batch of tests moved from tests/neg to tests/warn.
PR 3/5 (merge consecutively, per [Nicolas'
suggestion](#18829 (review))

Split up version of #18829
szymon-rd added a commit that referenced this pull request Jan 25, 2024
The last batch of tests, move tests other than tests/init/neg and
tests/neg to warn.
PR 4/5 (merge consecutively, per [Nicolas'
suggestion](#18829 (review))

Split up version of #18829
szymon-rd added a commit that referenced this pull request Jan 31, 2024
)

Final PR. Adds functionality that changes the behaviour of
fatal-warnings - fixes #18634
PR 5/5 (merge consecutively, per [Nicolas'
suggestion](#18829 (review))

Split up version of #18829
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not give up on compilation instantly when -Werror is on and warning appears
3 participants