Skip to content

Commit a7844ab

Browse files
committed
Add a 3.6-migration warning for MT lubbing
1 parent fd45847 commit a7844ab

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import annotation.tailrec
4040
import Implicits.*
4141
import util.Stats.record
4242
import config.Printers.{gadts, typr}
43-
import config.Feature, Feature.{sourceVersion, migrateTo3, modularity}
43+
import config.Feature, Feature.{migrateTo3, modularity, sourceVersion, warnOnMigration}
4444
import config.SourceVersion.*
4545
import rewrites.Rewrites, Rewrites.patch
4646
import staging.StagingLevel
@@ -2615,7 +2615,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
26152615
if !acc.exists then NoType
26162616
else if case1.body.tpe.isProvisional then NoType
26172617
else acc | case1.body.tpe
2618-
if lub.exists then TypeTree(lub, inferred = true)
2618+
if lub.exists then
2619+
if !lub.isAny then
2620+
val msg = em"Match type upper bound inferred as $lub, where previously it was defaulted to Any"
2621+
warnOnMigration(msg, tree, `3.6`)
2622+
TypeTree(lub, inferred = true)
26192623
else bound1
26202624
else bound1
26212625
assignType(cpy.MatchTypeTree(tree)(bound2, sel1, cases1), bound2, sel1, cases1)

tests/warn/i21258.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Migration Warning: tests/warn/i21258.scala:4:17 ---------------------------------------------------------------------
2+
4 | type MT[X] = X match { // warn
3+
| ^
4+
| Match type upper bound inferred as String, where previously it was defaulted to Any
5+
5 | case Int => String
6+
6 | }

tests/warn/i21258.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.language.`3.6-migration`
2+
3+
object Test {
4+
type MT[X] = X match { // warn
5+
case Int => String
6+
}
7+
8+
def unboundUnreducibleSig[X](x: X): MT[X] = ???
9+
10+
type MT2[X] = X match { // no warning
11+
case Int => String
12+
case String => Any
13+
}
14+
}

0 commit comments

Comments
 (0)