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