Skip to content

fix(#15784): ident rule for pat match was too strict #19501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 22, 2024
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,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.*
Expand Down
12 changes: 12 additions & 0 deletions tests/neg/i15784.check
Original file line number Diff line number Diff line change
@@ -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`
4 changes: 4 additions & 0 deletions tests/neg/i15784.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def i15784 = List(42) match
case List(_, Rest @ `a`) => Rest // error
case List(_, Rest @ A) => Rest // error
case _ => ???
8 changes: 8 additions & 0 deletions tests/pos/i15784.scala
Original file line number Diff line number Diff line change
@@ -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`