@@ -104,7 +104,7 @@ object Macros {
104104
105105 }
106106
107- def mergeTrait (tagKey : String , subtrees : Seq [Tree ], subtypes : Seq [Type ], targetType : c.Type ): Tree
107+ def mergeTrait (tagKey : Option [ String ] , subtrees : Seq [Tree ], subtypes : Seq [Type ], targetType : c.Type ): Tree
108108
109109 def derive (tpe : c.Type ) = {
110110 if (tpe.typeSymbol.asClass.isTrait || (tpe.typeSymbol.asClass.isAbstractClass && ! tpe.typeSymbol.isJava)) {
@@ -127,7 +127,7 @@ object Macros {
127127 " https://com-lihaoyi.github.io/upickle/#ManualSealedTraitPicklers"
128128 fail(tpe, msg)
129129 }else {
130- val tagKey = customKey(clsSymbol).getOrElse( Annotator .defaultTagKey)
130+ val tagKey = customKey(clsSymbol)
131131 val subTypes = fleshedOutSubtypes(tpe).toSeq.sortBy(_.typeSymbol.fullName)
132132 // println("deriveTrait")
133133 val subDerives = subTypes.map(subCls => q " implicitly[ ${typeclassFor(subCls)}] " )
@@ -241,7 +241,11 @@ object Macros {
241241 ).decodedName.toString
242242 )
243243
244- q " ${c.prefix}.annotate( $derived, $tagKey, $tagValue, $shortTagValue) "
244+ val tagKeyExpr = tagKey match {
245+ case Some (v) => q " $v"
246+ case None => q " ${c.prefix}.tagName "
247+ }
248+ q " ${c.prefix}.annotate( $derived, $tagKeyExpr, $tagValue, $shortTagValue) "
245249 }
246250 }
247251
@@ -363,8 +367,12 @@ object Macros {
363367 """
364368 }
365369
366- override def mergeTrait (tagKey : String , subtrees : Seq [Tree ], subtypes : Seq [Type ], targetType : c.Type ): Tree = {
367- q " ${c.prefix}.Reader.merge[ $targetType]( $tagKey, .. $subtrees) "
370+ override def mergeTrait (tagKey : Option [String ], subtrees : Seq [Tree ], subtypes : Seq [Type ], targetType : c.Type ): Tree = {
371+ val tagKeyExpr = tagKey match {
372+ case Some (v) => q " $v"
373+ case None => q " ${c.prefix}.tagName "
374+ }
375+ q " ${c.prefix}.Reader.merge[ $targetType]( $tagKeyExpr, .. $subtrees) "
368376 }
369377 }
370378
@@ -436,7 +444,7 @@ object Macros {
436444 """
437445 }
438446
439- override def mergeTrait (tagKey : String , subtree : Seq [Tree ], subtypes : Seq [Type ], targetType : c.Type ): Tree = {
447+ override def mergeTrait (tagKey : Option [ String ] , subtree : Seq [Tree ], subtypes : Seq [Type ], targetType : c.Type ): Tree = {
440448 q " ${c.prefix}.Writer.merge[ $targetType](.. $subtree) "
441449 }
442450 }
0 commit comments