@@ -433,6 +433,10 @@ object desugar {
433433 else originalTparams
434434 }
435435 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.
436440 val constrTparams = impliedTparams.map(toDefParam(_, keepAnnotations = false ))
437441 val constrVparamss =
438442 if (originalVparamss.isEmpty) { // ensure parameter list is non-empty
@@ -444,7 +448,14 @@ object desugar {
444448 ctx.error(CaseClassMissingNonImplicitParamList (cdef), namePos)
445449 ListOfNil
446450 }
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+
448459 val constr = cpy.DefDef (constr1)(tparams = constrTparams, vparamss = constrVparamss)
449460
450461 val (normalizedBody, enumCases, enumCompanionRef) = {
@@ -480,14 +491,6 @@ object desugar {
480491
481492 def anyRef = ref(defn.AnyRefAlias .typeRef)
482493
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-
491494 val arity = constrVparamss.head.length
492495
493496 val classTycon : Tree = TypeRefTree () // watching is set at end of method
@@ -779,8 +782,10 @@ object desugar {
779782 val originalVparamsIt = originalVparamss.iterator.flatten
780783 derivedVparamss match {
781784 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())))
784789 case _ =>
785790 Nil
786791 }
0 commit comments