Skip to content

Commit

Permalink
Add a 3.6-migration warning for MT lubbing
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Aug 6, 2024
1 parent fd45847 commit a7844ab
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests/warn/i21258.check
Original file line number Diff line number Diff line change
@@ -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 | }
14 changes: 14 additions & 0 deletions tests/warn/i21258.scala
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit a7844ab

Please sign in to comment.