Skip to content

Commit 15a0d05

Browse files
authored
Add a 3.6-migration warning for MT lubbing (#21336)
Fixes #21258, all the other parts having been addressed (reverting a change in binary erasure, which shipped in patch releases)
2 parents c09154a + a7844ab commit 15a0d05

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

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

+6-2
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

+6
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

+14
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)