Skip to content

Commit 8948092

Browse files
authored
Don't report warnings in migration when performing rewrites (#15589)
This PR stops reporting migration warnings when the given code snippet is also being rewritten. It fixes terrible development experience when combining `-rewrite -source .*-migration` with `-Xfatal-warnings`. In the mentioned case compilation would never succeed, since migration warnings elevated to errors, would always roll back generated rewrites. Since the warning message is not being shown in all paths I've changed the function arguments to be passed by name Sidenote: I've spent literally too much time wondering why -rewrites do not work as they should. I belive that typical Scala users would have the same problems.
2 parents 9009f16 + f8a7c5d commit 8948092

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

compiler/src/dotty/tools/dotc/report.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ object report:
8282

8383
def errorOrMigrationWarning(msg: Message, pos: SrcPos, from: SourceVersion)(using Context): Unit =
8484
if sourceVersion.isAtLeast(from) then
85-
if sourceVersion.isMigrating && sourceVersion.ordinal <= from.ordinal then migrationWarning(msg, pos)
85+
if sourceVersion.isMigrating && sourceVersion.ordinal <= from.ordinal then
86+
if ctx.settings.rewrite.value.isEmpty then migrationWarning(msg, pos)
8687
else error(msg, pos)
8788

8889
def gradualErrorOrMigrationWarning(msg: Message, pos: SrcPos, warnFrom: SourceVersion, errorFrom: SourceVersion)(using Context): Unit =

compiler/test/dotty/tools/dotc/CompilationTests.scala

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class CompilationTests {
8080
aggregateTests(
8181
compileFile("tests/rewrites/rewrites.scala", scala2CompatMode.and("-rewrite", "-indent")),
8282
compileFile("tests/rewrites/rewrites3x.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
83+
compileFile("tests/rewrites/rewrites3x.scala", defaultOptions.and("-rewrite", "-source", "future-migration", "-Xfatal-warnings")),
8384
compileFile("tests/rewrites/filtering-fors.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
8485
compileFile("tests/rewrites/refutable-pattern-bindings.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
8586
compileFile("tests/rewrites/i8982.scala", defaultOptions.and("-indent", "-rewrite")),

0 commit comments

Comments
 (0)