@@ -131,8 +131,13 @@ class GenCodecMacros(ctx: blackbox.Context) extends CodecMacroCommons(ctx) with
131131 }
132132 }
133133
134- def isTransientDefault (param : ApplyParam ): Boolean =
135- param.defaultValue.nonEmpty && hasAnnotation(param.sym, TransientDefaultAnnotType )
134+ def isTransientDefault (param : ApplyParam , warnIfDefaultNotProvided : Boolean = false ): Boolean =
135+ (hasAnnotation(param.sym, TransientDefaultAnnotType ), param.defaultValue.nonEmpty, warnIfDefaultNotProvided) match {
136+ case (true , false , true ) =>
137+ c.warning(param.sym.pos, s " @transientDefault has no effect on parameter ${param.sym.name} because it has no default value " )
138+ false
139+ case (hasAnnotation, noDefaultValue, _) => hasAnnotation && noDefaultValue
140+ }
136141
137142 def isOptimizedPrimitive (param : ApplyParam ): Boolean = {
138143 val vt = param.valueType
@@ -251,13 +256,13 @@ class GenCodecMacros(ctx: blackbox.Context) extends CodecMacroCommons(ctx) with
251256 }
252257
253258 def anyParamHasTransientDefault : Boolean =
254- params.exists(isTransientDefault)
259+ params.exists(isTransientDefault(_) )
255260
256261 def isOptionLike (p : ApplyParam ): Boolean =
257262 p.optionLike.nonEmpty
258263
259264 def mayBeTransient (p : ApplyParam ): Boolean =
260- isOptionLike(p) || isTransientDefault(p)
265+ isOptionLike(p) || isTransientDefault(p, warnIfDefaultNotProvided = true )
261266
262267 def transientValue (p : ApplyParam ): Tree = p.optionLike match {
263268 case Some (optionLike) => q " ${optionLike.reference(Nil )}.none "
@@ -614,7 +619,7 @@ class GenCodecMacros(ctx: blackbox.Context) extends CodecMacroCommons(ctx) with
614619 val deps = new mutable.ListBuffer [Tree ]
615620
616621 ttpe.members.iterator.foreach { getter =>
617- if (getter.isMethod && isJavaGetter(getter.asMethod)) {
622+ if (getter.isMethod && isJavaGetter(getter.asMethod)) {
618623 val propType = getter.typeSignatureIn(ttpe).finalResultType
619624 val getterName = getter.name.decodedName.toString
620625 val setterName = getterName.replaceFirst(" ^(get|is)" , " set" )
0 commit comments