@@ -452,6 +452,10 @@ object desugar {
452
452
else originalTparams
453
453
}
454
454
else originalTparams
455
+
456
+ // Annotations on class _type_ parameters are set on the derived parameters
457
+ // but not on the constructor parameters. The reverse is true for
458
+ // annotations on class _value_ parameters.
455
459
val constrTparams = impliedTparams.map(toDefParam(_, keepAnnotations = false ))
456
460
val constrVparamss =
457
461
if (originalVparamss.isEmpty) { // ensure parameter list is non-empty
@@ -463,7 +467,18 @@ object desugar {
463
467
ctx.error(CaseClassMissingNonImplicitParamList (cdef), namePos)
464
468
ListOfNil
465
469
}
466
- else originalVparamss.nestedMap(toDefParam(_, keepAnnotations = false ))
470
+ else originalVparamss.nestedMap(toDefParam(_, keepAnnotations = true ))
471
+ val derivedTparams = {
472
+ val impliedTparamsIt = impliedTparams.iterator
473
+ constrTparams.map(tparam => derivedTypeParam(tparam)
474
+ .withAnnotations(impliedTparamsIt.next().mods.annotations))
475
+ }
476
+ val derivedVparamss = {
477
+ val constrVparamsIt = constrVparamss.iterator.flatten
478
+ constrVparamss.nestedMap(vparam => derivedTermParam(vparam)
479
+ .withAnnotations(Nil ))
480
+ }
481
+
467
482
val constr = cpy.DefDef (constr1)(tparams = constrTparams, vparamss = constrVparamss)
468
483
469
484
val (normalizedBody, enumCases, enumCompanionRef) = {
@@ -499,19 +514,6 @@ object desugar {
499
514
500
515
def anyRef = ref(defn.AnyRefAlias .typeRef)
501
516
502
- // Annotations are dropped from the constructor parameters but should be
503
- // preserved in all derived parameters.
504
- val derivedTparams = {
505
- val impliedTparamsIt = impliedTparams.iterator
506
- constrTparams.map(tparam => derivedTypeParam(tparam)
507
- .withAnnotations(impliedTparamsIt.next().mods.annotations))
508
- }
509
- val derivedVparamss = {
510
- val constrVparamsIt = constrVparamss.iterator.flatten
511
- constrVparamss.nestedMap(vparam => derivedTermParam(vparam)
512
- .withAnnotations(constrVparamsIt.next().mods.annotations))
513
- }
514
-
515
517
val arity = constrVparamss.head.length
516
518
517
519
val classTycon : Tree = TypeRefTree () // watching is set at end of method
@@ -800,8 +802,10 @@ object desugar {
800
802
val originalVparamsIt = originalVparamss.iterator.flatten
801
803
derivedVparamss match {
802
804
case first :: rest =>
803
- first.map(_.withMods(originalVparamsIt.next().mods | caseAccessor)) ++
804
- rest.flatten.map(_.withMods(originalVparamsIt.next().mods))
805
+ // Annotations on the class _value_ parameters are not set on the parameter accessors
806
+ def mods (vdef : ValDef ) = vdef.mods.withAnnotations(Nil )
807
+ first.map(_.withMods(mods(originalVparamsIt.next()) | caseAccessor)) ++
808
+ rest.flatten.map(_.withMods(mods(originalVparamsIt.next())))
805
809
case _ =>
806
810
Nil
807
811
}
0 commit comments