Skip to content

Commit 75eae18

Browse files
committed
Change to new syntax
1 parent 67e3bb5 commit 75eae18

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

tests/run-macros/i6988/FirstArg_1.scala

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,29 @@ package foo
22

33
case class FirstArg(value: Any, source: String)
44
object FirstArg {
5-
inline given as FirstArg = ${Macros.argsImpl}
5+
inline given FirstArg = ${Macros.argsImpl}
66
}
77

88
object Macros {
9-
import language.experimental.macros
109
import scala.quoted._
11-
import scala.tasty._
1210

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+
1616
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+
2623
def literal(value: String): Expr[String] =
2724
Literal(Constant(value)).seal.asInstanceOf[Expr[String]]
2825
val paramss = enclosingParamList(rootContext.owner)
2926
val firstArg = paramss.flatten.head
3027
val ref = Select.unique(This(enclosingCls), firstArg.name)
31-
'{ FirstArg(${ref.seal}, ${firstArg.name.toExpr}) }
28+
'{ FirstArg(${ref.seal}, ${Expr(firstArg.name)}) }
3229
}
33-
}
30+
}

0 commit comments

Comments
 (0)