@@ -267,8 +267,8 @@ object desugar {
267
267
def defaultGetter : DefDef =
268
268
DefDef (
269
269
name = DefaultGetterName (methName, n),
270
- tparams = meth.tparams.map(tparam => dropContextBounds(toDefParam(tparam))),
271
- vparamss = takeUpTo(normalizedVparamss.nestedMap(toDefParam), n),
270
+ tparams = meth.tparams.map(tparam => dropContextBounds(toDefParam(tparam, keepAnnotations = true ))),
271
+ vparamss = takeUpTo(normalizedVparamss.nestedMap(toDefParam(_, keepAnnotations = true ) ), n),
272
272
tpt = TypeTree (),
273
273
rhs = vparam.rhs
274
274
)
@@ -372,10 +372,16 @@ object desugar {
372
372
373
373
@ sharable private val synthetic = Modifiers (Synthetic )
374
374
375
- private def toDefParam (tparam : TypeDef ): TypeDef =
376
- tparam.withMods(tparam.rawMods & EmptyFlags | Param )
377
- private def toDefParam (vparam : ValDef ): ValDef =
378
- vparam.withMods(vparam.rawMods & (GivenOrImplicit | Erased ) | Param )
375
+ private def toDefParam (tparam : TypeDef , keepAnnotations : Boolean ): TypeDef = {
376
+ var mods = tparam.rawMods
377
+ if (! keepAnnotations) mods = mods.withAnnotations(Nil )
378
+ tparam.withMods(mods & EmptyFlags | Param )
379
+ }
380
+ private def toDefParam (vparam : ValDef , keepAnnotations : Boolean ): ValDef = {
381
+ var mods = vparam.rawMods
382
+ if (! keepAnnotations) mods = mods.withAnnotations(Nil )
383
+ vparam.withMods(mods & (GivenOrImplicit | Erased ) | Param )
384
+ }
379
385
380
386
/** The expansion of a class definition. See inline comments for what is involved */
381
387
def classDef (cdef : TypeDef )(implicit ctx : Context ): Tree = {
@@ -437,7 +443,7 @@ object desugar {
437
443
else originalTparams
438
444
}
439
445
else originalTparams
440
- val constrTparams = impliedTparams.map(toDefParam)
446
+ val constrTparams = impliedTparams.map(toDefParam(_, keepAnnotations = false ) )
441
447
val constrVparamss =
442
448
if (originalVparamss.isEmpty) { // ensure parameter list is non-empty
443
449
if (isCaseClass && originalTparams.isEmpty)
@@ -447,7 +453,7 @@ object desugar {
447
453
ctx.error(" Case classes should have a non-implicit parameter list" , namePos)
448
454
ListOfNil
449
455
}
450
- else originalVparamss.nestedMap(toDefParam)
456
+ else originalVparamss.nestedMap(toDefParam(_, keepAnnotations = false ) )
451
457
val constr = cpy.DefDef (constr1)(tparams = constrTparams, vparamss = constrVparamss)
452
458
453
459
val (normalizedBody, enumCases, enumCompanionRef) = {
@@ -459,7 +465,7 @@ object desugar {
459
465
defDef(
460
466
addEvidenceParams(
461
467
cpy.DefDef (ddef)(tparams = constrTparams),
462
- evidenceParams(constr1).map(toDefParam))))
468
+ evidenceParams(constr1).map(toDefParam(_, keepAnnotations = false ) ))))
463
469
case stat =>
464
470
stat
465
471
}
@@ -482,8 +488,19 @@ object desugar {
482
488
483
489
def anyRef = ref(defn.AnyRefAlias .typeRef)
484
490
485
- val derivedTparams = constrTparams.map(derivedTypeParam(_))
486
- val derivedVparamss = constrVparamss.nestedMap(derivedTermParam(_))
491
+ // Annotations are dropped from the constructor parameters but should be
492
+ // preserved in all derived parameters.
493
+ val derivedTparams = {
494
+ val impliedTparamsIt = impliedTparams.toIterator
495
+ constrTparams.map(tparam => derivedTypeParam(tparam)
496
+ .withAnnotations(impliedTparamsIt.next().mods.annotations))
497
+ }
498
+ val derivedVparamss = {
499
+ val constrVparamsIt = constrVparamss.toIterator.flatten
500
+ constrVparamss.nestedMap(vparam => derivedTermParam(vparam)
501
+ .withAnnotations(constrVparamsIt.next().mods.annotations))
502
+ }
503
+
487
504
val arity = constrVparamss.head.length
488
505
489
506
val classTycon : Tree = TypeRefTree () // watching is set at end of method
@@ -772,16 +789,20 @@ object desugar {
772
789
}
773
790
774
791
val cdef1 = addEnumFlags {
775
- val originalTparamsIt = impliedTparams.toIterator
776
- val originalVparamsIt = originalVparamss.toIterator.flatten
777
- val tparamAccessors = derivedTparams.map(_.withMods(originalTparamsIt.next().mods))
792
+ val tparamAccessors = {
793
+ val impliedTparamsIt = impliedTparams.toIterator
794
+ derivedTparams.map(_.withMods(impliedTparamsIt.next().mods))
795
+ }
778
796
val caseAccessor = if (isCaseClass) CaseAccessor else EmptyFlags
779
- val vparamAccessors = derivedVparamss match {
780
- case first :: rest =>
781
- first.map(_.withMods(originalVparamsIt.next().mods | caseAccessor)) ++
782
- rest.flatten.map(_.withMods(originalVparamsIt.next().mods))
783
- case _ =>
784
- Nil
797
+ val vparamAccessors = {
798
+ val originalVparamsIt = originalVparamss.toIterator.flatten
799
+ derivedVparamss match {
800
+ case first :: rest =>
801
+ first.map(_.withMods(originalVparamsIt.next().mods | caseAccessor)) ++
802
+ rest.flatten.map(_.withMods(originalVparamsIt.next().mods))
803
+ case _ =>
804
+ Nil
805
+ }
785
806
}
786
807
cpy.TypeDef (cdef : TypeDef )(
787
808
name = className,
0 commit comments