File tree Expand file tree Collapse file tree 5 files changed +23
-4
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 5 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -353,6 +353,12 @@ object Trees {
353353 }
354354 }
355355 else span
356+
357+ /** The source position of the name defined by this definition.
358+ * This is a point position if the definition is synthetic, or a range position
359+ * if the definition comes from source.
360+ */
361+ def namePos : SourcePosition = source.atSpan(nameSpan)
356362 }
357363
358364 /** Tree defines a new symbol and carries modifiers.
Original file line number Diff line number Diff line change @@ -229,6 +229,10 @@ trait QuotesAndSplices {
229229 }
230230 }
231231 cpy.AppliedTypeTree (tree)(transform(tpt), args1)
232+ case tree : NamedDefTree =>
233+ if tree.name.isTermName && ! tree.nameSpan.isSynthetic && tree.name.startsWith(" $" ) then
234+ ctx.error(" Names cannot start with $ quote pattern " , tree.namePos)
235+ super .transform(tree)
232236 case _ =>
233237 super .transform(tree)
234238 }
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 11object Test {
22 def test (x : quoted.Expr [Int ])(using scala.quoted.QuoteContext ) = x match {
3- case ' { val `$y` : Int = 2 ; 1 } =>
3+ case ' { val `$y` : Int = 2 ; 1 } => // error
44 y // error: Not found: y
5- case ' { ((`$y` : Int ) => 3 ); 2 } =>
5+ case ' { ((`$y` : Int ) => 3 ); 2 } => // error
66 y // error: Not found: y
7- case ' { def `$f` : Int = 8 ; 2 } =>
7+ case ' { def `$f` : Int = 8 ; 2 } => // error
88 f // error: Not found: f
99 case _ =>
1010 }
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ object Macro {
55 inline def mac (inline tree : Any ): String = $ { macImpl(' tree ) }
66 def macImpl (tree : Expr [Any ])(using qctx : QuoteContext ): Expr [String ] = {
77 tree match {
8- case ' { ($ in : $tpe1) => ($out : $tpe2) } => Expr (out.toString)
8+ case ' { (in : $tpe1) => ($out : $tpe2) } => Expr (out.toString)
99 case _ => Expr (" not matched" )
1010 }
1111 }
You can’t perform that action at this time.
0 commit comments