diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index e7a2408d2b2b..7728ab06d089 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -934,7 +934,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer * (x: T) to (x @ (w: T)). This is either `_` or `_*`. */ def cases(ifPat: => Tree, ifExpr: => Tree, wildName: TermName) = tree.expr match { - case id: untpd.Ident if (ctx.mode is Mode.Pattern) && untpd.isVarPattern(id) => + case id: untpd.Ident if (ctx.mode is Mode.Pattern) => if (id.name == nme.WILDCARD || id.name == nme.WILDCARD_STAR) ifPat else { import untpd.* diff --git a/tests/neg/i15784.check b/tests/neg/i15784.check new file mode 100644 index 000000000000..c1540b33d956 --- /dev/null +++ b/tests/neg/i15784.check @@ -0,0 +1,12 @@ +-- [E006] Not Found Error: tests/neg/i15784.scala:2:22 ----------------------------------------------------------------- +2 | case List(_, Rest @ `a`) => Rest // error + | ^^^ + | Not found: a + | + | longer explanation available when compiling with `-explain` +-- [E006] Not Found Error: tests/neg/i15784.scala:3:22 ----------------------------------------------------------------- +3 | case List(_, Rest @ A) => Rest // error + | ^ + | Not found: A + | + | longer explanation available when compiling with `-explain` diff --git a/tests/neg/i15784.scala b/tests/neg/i15784.scala new file mode 100644 index 000000000000..a58a27fb3cfa --- /dev/null +++ b/tests/neg/i15784.scala @@ -0,0 +1,4 @@ +def i15784 = List(42) match + case List(_, Rest @ `a`) => Rest // error + case List(_, Rest @ A) => Rest // error + case _ => ??? \ No newline at end of file diff --git a/tests/pos/i15784.scala b/tests/pos/i15784.scala new file mode 100644 index 000000000000..ab4b82638a42 --- /dev/null +++ b/tests/pos/i15784.scala @@ -0,0 +1,8 @@ +def i15784 = List(42) match + case List(_, rest @ _*) => rest + case List(_, Rest @ _*) => Rest + case List(_, `Rest` @ _*) => Rest + case _ => ??? + +def i15784_auxiliary = 42 match + case `type` : Int => `type`