Skip to content

Commit 1c2eb3b

Browse files
committed
Fix #8749: Warn on $ at the start of a name in quoted patterns
These are just part of the name.
1 parent 755a81f commit 1c2eb3b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ trait QuotesAndSplices {
229229
}
230230
}
231231
cpy.AppliedTypeTree(tree)(transform(tpt), args1)
232+
case tree: NamedDefTree =>
233+
if !tree.nameSpan.isSynthetic && tree.symbol.name.startsWith("$") then
234+
ctx.error("Names cannot start with $ quote pattern", ctx.source.atSpan(tree.nameSpan))
235+
super.transform(tree)
232236
case _ =>
233237
super.transform(tree)
234238
}

tests/neg/i8749.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.quoted._
2+
3+
object FunObject {
4+
def fun(t: String => String) = t
5+
}
6+
7+
def test(using QuoteContext)(x: Expr[String => String]) =
8+
x match
9+
case '{ FunObject.fun(($arg: String) => $out) } => // error

0 commit comments

Comments
 (0)