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 {
353
353
}
354
354
}
355
355
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)
356
362
}
357
363
358
364
/** Tree defines a new symbol and carries modifiers.
Original file line number Diff line number Diff line change @@ -229,6 +229,10 @@ trait QuotesAndSplices {
229
229
}
230
230
}
231
231
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)
232
236
case _ =>
233
237
super .transform(tree)
234
238
}
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 1
1
object Test {
2
2
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
4
4
y // error: Not found: y
5
- case ' { ((`$y` : Int ) => 3 ); 2 } =>
5
+ case ' { ((`$y` : Int ) => 3 ); 2 } => // error
6
6
y // error: Not found: y
7
- case ' { def `$f` : Int = 8 ; 2 } =>
7
+ case ' { def `$f` : Int = 8 ; 2 } => // error
8
8
f // error: Not found: f
9
9
case _ =>
10
10
}
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ object Macro {
5
5
inline def mac (inline tree : Any ): String = $ { macImpl(' tree ) }
6
6
def macImpl (tree : Expr [Any ])(using qctx : QuoteContext ): Expr [String ] = {
7
7
tree match {
8
- case ' { ($ in : $tpe1) => ($out : $tpe2) } => Expr (out.toString)
8
+ case ' { (in : $tpe1) => ($out : $tpe2) } => Expr (out.toString)
9
9
case _ => Expr (" not matched" )
10
10
}
11
11
}
You can’t perform that action at this time.
0 commit comments