@@ -433,6 +433,10 @@ object desugar {
433
433
else originalTparams
434
434
}
435
435
else originalTparams
436
+
437
+ // Annotations on class _type_ parameters are set on the derived parameters
438
+ // but not on the constructor parameters. The reverse is true for
439
+ // annotations on class _value_ parameters.
436
440
val constrTparams = impliedTparams.map(toDefParam(_, keepAnnotations = false ))
437
441
val constrVparamss =
438
442
if (originalVparamss.isEmpty) { // ensure parameter list is non-empty
@@ -444,7 +448,14 @@ object desugar {
444
448
ctx.error(CaseClassMissingNonImplicitParamList (cdef), namePos)
445
449
ListOfNil
446
450
}
447
- else originalVparamss.nestedMap(toDefParam(_, keepAnnotations = false , keepDefault = true ))
451
+ else originalVparamss.nestedMap(toDefParam(_, keepAnnotations = true , keepDefault = true ))
452
+ val derivedTparams =
453
+ constrTparams.zipWithConserve(impliedTparams)((tparam, impliedParam) =>
454
+ derivedTypeParam(tparam).withAnnotations(impliedParam.mods.annotations))
455
+ val derivedVparamss =
456
+ constrVparamss.nestedMap(vparam =>
457
+ derivedTermParam(vparam).withAnnotations(Nil ))
458
+
448
459
val constr = cpy.DefDef (constr1)(tparams = constrTparams, vparamss = constrVparamss)
449
460
450
461
val (normalizedBody, enumCases, enumCompanionRef) = {
@@ -480,14 +491,6 @@ object desugar {
480
491
481
492
def anyRef = ref(defn.AnyRefAlias .typeRef)
482
493
483
- // Annotations are dropped from the constructor parameters but should be
484
- // preserved in all derived parameters.
485
- val derivedTparams =
486
- constrTparams.zipWithConserve(impliedTparams)((tparam, impliedParam) =>
487
- derivedTypeParam(tparam).withAnnotations(impliedParam.mods.annotations))
488
- val derivedVparamss =
489
- constrVparamss.nestedMap(vparam => derivedTermParam(vparam))
490
-
491
494
val arity = constrVparamss.head.length
492
495
493
496
val classTycon : Tree = TypeRefTree () // watching is set at end of method
@@ -779,8 +782,10 @@ object desugar {
779
782
val originalVparamsIt = originalVparamss.iterator.flatten
780
783
derivedVparamss match {
781
784
case first :: rest =>
782
- first.map(_.withMods(originalVparamsIt.next().mods | caseAccessor)) ++
783
- rest.flatten.map(_.withMods(originalVparamsIt.next().mods))
785
+ // Annotations on the class _value_ parameters are not set on the parameter accessors
786
+ def mods (vdef : ValDef ) = vdef.mods.withAnnotations(Nil )
787
+ first.map(_.withMods(mods(originalVparamsIt.next()) | caseAccessor)) ++
788
+ rest.flatten.map(_.withMods(mods(originalVparamsIt.next())))
784
789
case _ =>
785
790
Nil
786
791
}
0 commit comments