Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-3544

Macro for case class with default values fails to compile

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Scala
    • Labels:
      None

      I'm following up on this issue. After updating the minimal github repo with Ross' suggestion, compilation still failed with the same error.

      So I dug into the macro, and the way default args are handled caught my eye:

      def defaultClassArgs = {
        val terms = mainType.decl(termNames.CONSTRUCTOR).asMethod.paramLists match {
          case h :: _ => h.map(_.asTerm)
          case _ => List.empty
        }
        val params = terms.zipWithIndex.collect {
          case (s, i) if s.isParamWithDefault => {
            val getterName = TermName("apply$default$" + (i + 1))
            q"${s.name.toString} -> ${mainType.typeSymbol.companion}.$getterName"
          }
        }
        c.Expr[Map[String, Any]](q"Map[String, Any](..$params)")
      }
      
      ...
      
      val classFieldDefaultArgsMap = $defaultClassArgs
      

      Looks like default args are being stored as vals. This approach seems like it would work for simple defaults, like strings or ints. But would it work for lambda-based defaults, like ObjectId.get?

            Assignee:
            Unassigned Unassigned
            Reporter:
            fedenusy13 Federico Nusymowicz
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: