@@ -131,8 +131,13 @@ class GenCodecMacros(ctx: blackbox.Context) extends CodecMacroCommons(ctx) with
131
131
}
132
132
}
133
133
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
+ }
136
141
137
142
def isOptimizedPrimitive (param : ApplyParam ): Boolean = {
138
143
val vt = param.valueType
@@ -251,13 +256,13 @@ class GenCodecMacros(ctx: blackbox.Context) extends CodecMacroCommons(ctx) with
251
256
}
252
257
253
258
def anyParamHasTransientDefault : Boolean =
254
- params.exists(isTransientDefault)
259
+ params.exists(isTransientDefault(_) )
255
260
256
261
def isOptionLike (p : ApplyParam ): Boolean =
257
262
p.optionLike.nonEmpty
258
263
259
264
def mayBeTransient (p : ApplyParam ): Boolean =
260
- isOptionLike(p) || isTransientDefault(p)
265
+ isOptionLike(p) || isTransientDefault(p, warnIfDefaultNotProvided = true )
261
266
262
267
def transientValue (p : ApplyParam ): Tree = p.optionLike match {
263
268
case Some (optionLike) => q " ${optionLike.reference(Nil )}.none "
@@ -614,7 +619,7 @@ class GenCodecMacros(ctx: blackbox.Context) extends CodecMacroCommons(ctx) with
614
619
val deps = new mutable.ListBuffer [Tree ]
615
620
616
621
ttpe.members.iterator.foreach { getter =>
617
- if (getter.isMethod && isJavaGetter(getter.asMethod)) {
622
+ if (getter.isMethod && isJavaGetter(getter.asMethod)) {
618
623
val propType = getter.typeSignatureIn(ttpe).finalResultType
619
624
val getterName = getter.name.decodedName.toString
620
625
val setterName = getterName.replaceFirst(" ^(get|is)" , " set" )
0 commit comments