diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 947d1fcbfa73..ace8439553fd 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -40,7 +40,7 @@ import annotation.tailrec import Implicits.* import util.Stats.record import config.Printers.{gadts, typr} -import config.Feature, Feature.{sourceVersion, migrateTo3, modularity} +import config.Feature, Feature.{migrateTo3, modularity, sourceVersion, warnOnMigration} import config.SourceVersion.* import rewrites.Rewrites, Rewrites.patch import staging.StagingLevel @@ -2615,7 +2615,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer if !acc.exists then NoType else if case1.body.tpe.isProvisional then NoType else acc | case1.body.tpe - if lub.exists then TypeTree(lub, inferred = true) + if lub.exists then + if !lub.isAny then + val msg = em"Match type upper bound inferred as $lub, where previously it was defaulted to Any" + warnOnMigration(msg, tree, `3.6`) + TypeTree(lub, inferred = true) else bound1 else bound1 assignType(cpy.MatchTypeTree(tree)(bound2, sel1, cases1), bound2, sel1, cases1) diff --git a/tests/warn/i21258.check b/tests/warn/i21258.check new file mode 100644 index 000000000000..e9edc3606909 --- /dev/null +++ b/tests/warn/i21258.check @@ -0,0 +1,6 @@ +-- Migration Warning: tests/warn/i21258.scala:4:17 --------------------------------------------------------------------- +4 | type MT[X] = X match { // warn + | ^ + | Match type upper bound inferred as String, where previously it was defaulted to Any +5 | case Int => String +6 | } diff --git a/tests/warn/i21258.scala b/tests/warn/i21258.scala new file mode 100644 index 000000000000..60c6f859bc24 --- /dev/null +++ b/tests/warn/i21258.scala @@ -0,0 +1,14 @@ +import scala.language.`3.6-migration` + +object Test { + type MT[X] = X match { // warn + case Int => String + } + + def unboundUnreducibleSig[X](x: X): MT[X] = ??? + + type MT2[X] = X match { // no warning + case Int => String + case String => Any + } +}