shayan
shayan

Reputation: 1241

Scala 3 quotes: get default case class field value

I've been trying to access the default value of a declared case class's field by trying various functions on the quote's Symbol API, but with no luck so far:

case class User(name: String = "Shayan")

given scala.quoted.staging.Compiler = scala.quoted.staging.Compiler.make(getClass.getClassLoader)

scala.quoted.staging.withQuotes { q ?=>
   import q.reflect.*

   // Inspecting the `caseFields` symbols was my instinctive first approach:
   TypeRepr.of[User].classSymbol.get.caseFields
   // or
   TypeRepr.of[User].typeSymbol.caseFields   

   /*
     Even the `Symbol.tree` method that the docs warn against using, and 
     returns the most comprehensive info I've encountered thus far does not
     include the default parameter information:
   */
   TypeRepr.of[User].classSymbol.get.tree.show(using Printer.TreeAnsiCode)
   // or
   TypeRepr.of[User].typeSymbol.tree.show(using Printer.TreeAnsiCode)
}

Is there any way to access the default parameter's value information in the current TASTy API?

Upvotes: 1

Views: 32

Answers (0)

Related Questions