From 0000d23e7530cded8df5637f7aa295fa5fd89302 Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Mon, 29 Jul 2024 15:27:06 +0200 Subject: [PATCH] Only replace *new* errors by warnings under `-migration` 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. --- compiler/src/dotty/tools/dotc/report.scala | 2 +- tests/neg/migrate-once.scala | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 tests/neg/migrate-once.scala diff --git a/compiler/src/dotty/tools/dotc/report.scala b/compiler/src/dotty/tools/dotc/report.scala index 1d8ca5f208fa..c77d4eb2fc7e 100644 --- a/compiler/src/dotty/tools/dotc/report.scala +++ b/compiler/src/dotty/tools/dotc/report.scala @@ -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) diff --git a/tests/neg/migrate-once.scala b/tests/neg/migrate-once.scala new file mode 100644 index 000000000000..da5b76e4fb8c --- /dev/null +++ b/tests/neg/migrate-once.scala @@ -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