Skip to content

Commit 3c3a06d

Browse files
defaultParams returns Symbols
Co-authored-by: Nicolas Stucki <nicolas.stucki@gmail.com> Update tests
1 parent b99faf8 commit 3c3a06d

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,19 +1779,19 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
17791779
case sym if sym.is(Flags.CaseAccessor) => sym.asTerm
17801780
}
17811781

1782-
def Symbol_defaultParams(self: Symbol)(using ctx: Context): Map[String, Ref] =
1782+
def Symbol_defaultParams(self: Symbol)(using ctx: Context): Map[String, Symbol] =
17831783
assert(self.isClass && self.flags.is(Flags.Case))
17841784
val comp: Symbol = self.companionClass
17851785
val names: List[String] =
17861786
for p <- Symbol_caseFields(self) if p.flags.is(Flags.HasDefault)
17871787
yield Symbol_name(p)
17881788

17891789
val body = ClassDef_body(Symbol_tree(comp).asInstanceOf[ClassDef])
1790-
val idents: List[Ref] =
1791-
for case deff @ DefDef(name, _, _, _, tree) <- body
1790+
val idents: List[Symbol] =
1791+
for case deff @ DefDef(name, Nil, Nil, _, _) <- body
17921792
if name.toString.startsWith("$lessinit$greater$default")
1793-
yield Ref_apply(deff.symbol)
1794-
1793+
yield deff.symbol
1794+
assert(names.size == idents.size)
17951795
names.zip(idents).toMap
17961796
end Symbol_defaultParams
17971797

library/src/scala/tasty/Reflection.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2289,7 +2289,7 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
22892289
* Implementation restriction: only the default parameters in the first parameter group
22902290
* are returned.
22912291
*/
2292-
def defaultParams(using ctx: Context): Map[String, Ref] =
2292+
def defaultParams(using ctx: Context): Map[String, Symbol] =
22932293
internal.Symbol_defaultParams(sym)
22942294

22952295
def isTypeParam(using ctx: Context): Boolean =

library/src/scala/tasty/reflect/CompilerInterface.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ trait CompilerInterface {
13371337
* Implementation restriction: only the default parameters in the first parameter group
13381338
* are returned.
13391339
*/
1340-
def Symbol_defaultParams(self: Symbol)(using ctx: Context): Map[String, Ref]
1340+
def Symbol_defaultParams(self: Symbol)(using ctx: Context): Map[String, Symbol]
13411341

13421342
def Symbol_of(fullName: String)(using ctx: Context): Symbol
13431343

tests/run-macros/reflect-defaultParams/Macro_1.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ private def defaultParamsImpl[T](
66
import qctx.tasty._
77
val sym = tpe.unseal.symbol
88
val exprs: Map[String, Expr[Any]] =
9-
sym.defaultParams.view.mapValues(_.seal.cast[Any]).toMap
9+
sym.defaultParams.view.mapValues(sym =>
10+
Ref(sym).seal.cast[Any]).toMap
1011
Expr.ofMapValues(exprs)
1112
end defaultParamsImpl
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
case class Cat(name: String, address: String = "Home", age: Int = 1)
1+
case class Cat(name: String, address: String = "Home",
2+
age: Int = 1)(a: Int = age, b: String = address + age)
23

34
@main def Test =
4-
println(defaultParams[Cat])
5+
println(defaultParams[Cat].toList.sortBy(_._1))

0 commit comments

Comments
 (0)