diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 237f48d7bd96..34940d2f5277 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -668,7 +668,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer if ctx.mode.is(Mode.Pattern) && !tree.isType && !pt.isInstanceOf[ApplyingProto] - && !tree.tpe.isStable + && !tree.tpe.match + case tp: NamedType => tp.denot.hasAltWith(_.symbol.isStableMember && tp.prefix.isStable || tp.info.isStable) + case tp => tp.isStable && !isWildcardArg(tree) then report.error(StableIdentPattern(tree, pt), tree.srcPos) diff --git a/tests/pos/i18247.scala b/tests/pos/i18247.scala new file mode 100644 index 000000000000..b3805f5a7d02 --- /dev/null +++ b/tests/pos/i18247.scala @@ -0,0 +1,10 @@ +sealed trait Op +object Op { + case object `==` extends Op +} + +def t1(a: Op): true = { + a match { + case Op.`==` => true // was: won't compile + } +}