Skip to content

Commit 19ed7ad

Browse files
committed
Check patvar names
1 parent 81fb624 commit 19ed7ad

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,6 +3425,9 @@ object Parsers {
34253425
p = atSpan(startOffset(t), in.offset) { TypeApply(p, typeArgs(namedOK = false, wildOK = false)) }
34263426
if (in.token == LPAREN)
34273427
p = atSpan(startOffset(t), in.offset) { Apply(p, argumentPatterns()) }
3428+
p match
3429+
case nt: NameTree if isVarPattern(nt) => checkName(nt)
3430+
case _ =>
34283431
p
34293432

34303433
/** Patterns ::= Pattern [`,' Pattern]

tests/neg/i18234.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,8 @@ package BadPackageEnd$ : // error
162162

163163
class BadConstructor:
164164
def `<init>`() = () // error // error
165+
166+
def patvar[A](x: Option[A]) =
167+
x match
168+
case Some(funky$thing) => true // error
169+
case _ => false

tests/pos/i18234.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//> using options -Werror
12

23
class `C$Z`:
34
override def toString = "C$Z"
5+
6+
def patvar[A](x: Option[A]) =
7+
x match
8+
case Some(`funky$thing` @ _) => true
9+
case _ => false

0 commit comments

Comments
 (0)