@@ -2,32 +2,29 @@ package foo
2
2
3
3
case class FirstArg (value : Any , source : String )
4
4
object FirstArg {
5
- inline given as FirstArg = $ {Macros .argsImpl}
5
+ inline given FirstArg = $ {Macros .argsImpl}
6
6
}
7
7
8
8
object Macros {
9
- import language .experimental .macros
10
9
import scala .quoted ._
11
- import scala .tasty ._
12
10
13
- def argsImpl given (qctx : QuoteContext ): Expr [FirstArg ] = {
14
- import qctx .tasty ._
15
- var enclosingCls : ClassDefSymbol = rootContext.owner.asInstanceOf [ClassDefSymbol ]
11
+ def argsImpl (given qctx : QuoteContext ): Expr [FirstArg ] = {
12
+ import qctx .tasty .{_ , given }
13
+
14
+ var enclosingCls : Symbol = rootContext.owner
15
+
16
16
def enclosingParamList (owner : Symbol ): Seq [Seq [Symbol ]] =
17
- owner match {
18
- case IsClassDefSymbol (x) =>
19
- enclosingCls = x
20
- x.tree.constructor.paramss map { _ map {
21
- _.symbol
22
- }}
23
- case _ =>
24
- enclosingParamList(owner.owner)
25
- }
17
+ if owner.isClassDef then
18
+ owner.tree match
19
+ case tdef : ClassDef =>
20
+ tdef.constructor.paramss map { _ map {_.symbol }}
21
+ else enclosingParamList(owner.owner)
22
+
26
23
def literal (value : String ): Expr [String ] =
27
24
Literal (Constant (value)).seal.asInstanceOf [Expr [String ]]
28
25
val paramss = enclosingParamList(rootContext.owner)
29
26
val firstArg = paramss.flatten.head
30
27
val ref = Select .unique(This (enclosingCls), firstArg.name)
31
- ' { FirstArg ($ {ref.seal}, $ {firstArg.name.toExpr }) }
28
+ ' { FirstArg ($ {ref.seal}, $ {Expr ( firstArg.name) }) }
32
29
}
33
- }
30
+ }
0 commit comments