Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}