Skip to content

Commit

Permalink
Only replace *new* errors by warnings under -migration
Browse files Browse the repository at this point in the history
This makes `errorOrMigrationWarning` monotonic
from the sourceVersion onto ok < warn < error

For example, ForComprehensionPatternWithoutCase:
- became an error in 3.4,
- was hence a warning in 3.4-migration,
- but it should still be an error in 3.5-migration.
  • Loading branch information
EugeneFlesselle committed Jul 31, 2024
1 parent 5da1855 commit 0000d23
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ object report:

def errorOrMigrationWarning(msg: Message, pos: SrcPos, migrationVersion: MigrationVersion)(using Context): Unit =
if sourceVersion.isAtLeast(migrationVersion.errorFrom) then
if !sourceVersion.isMigrating then error(msg, pos)
if sourceVersion != migrationVersion.errorFrom.prevMigrating then error(msg, pos)
else if ctx.settings.rewrite.value.isEmpty then migrationWarning(msg, pos)
else if sourceVersion.isAtLeast(migrationVersion.warnFrom) then warning(msg, pos)

Expand Down
5 changes: 5 additions & 0 deletions tests/neg/migrate-once.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//> using options -source:3.5-migration

object Test:
for Some(x) <- Seq(Option(1)) yield x // error
// was warn before changes, but should warn only until 3.4-migration

0 comments on commit 0000d23

Please sign in to comment.