Skip to content

Commit 0e01547

Browse files
authored
Backport "Disallow overloading from breaking stable patterns" to LTS (#19163)
Backports #18327 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 96af022 + c43d387 commit 0e01547

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
668668
if ctx.mode.is(Mode.Pattern)
669669
&& !tree.isType
670670
&& !pt.isInstanceOf[ApplyingProto]
671-
&& !tree.tpe.isStable
671+
&& !tree.tpe.match
672+
case tp: NamedType => tp.denot.hasAltWith(_.symbol.isStableMember && tp.prefix.isStable || tp.info.isStable)
673+
case tp => tp.isStable
672674
&& !isWildcardArg(tree)
673675
then
674676
report.error(StableIdentPattern(tree, pt), tree.srcPos)

tests/pos/i18247.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
sealed trait Op
2+
object Op {
3+
case object `==` extends Op
4+
}
5+
6+
def t1(a: Op): true = {
7+
a match {
8+
case Op.`==` => true // was: won't compile
9+
}
10+
}

0 commit comments

Comments
 (0)