Skip to content

Commit b6f1ea5

Browse files
committed
Always keep annotations on value parameters for class methods
The previous code always dropped annotations from all constructor parameters and also from all parameters of derived methods such as copy and apply. That last part was an error: there was code that meant to compensate for it, but because of a typo the compensation code did nothing. The commit that dropped parameters was b602d83 "Drop annotations from constructor parameters". That commit had as motivation that cyclic references could be avoided by dropping @specialized on type parameters. So by that logic it seems safe to keep annotations on value parameters of constructors. This could be important if (say) we have an annotation indicating default arguments, which certainly will have to be kept on the constructor as well.
1 parent 2ee8adf commit b6f1ea5

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ object desugar {
277277
DefDef(
278278
name = DefaultGetterName(methName, n),
279279
tparams = meth.tparams.map(tparam => dropContextBounds(toDefParam(tparam, keepAnnotations = true))),
280-
vparamss = takeUpTo(normalizedVparamss.nestedMap(toDefParam(_, keepAnnotations = true)), n),
280+
vparamss = takeUpTo(normalizedVparamss.nestedMap(toDefParam(_)), n),
281281
tpt = TypeTree(),
282282
rhs = vparam.rhs
283283
)
@@ -386,11 +386,8 @@ object desugar {
386386
if (!keepAnnotations) mods = mods.withAnnotations(Nil)
387387
tparam.withMods(mods & EmptyFlags | Param)
388388
}
389-
private def toDefParam(vparam: ValDef, keepAnnotations: Boolean): ValDef = {
390-
var mods = vparam.rawMods
391-
if (!keepAnnotations) mods = mods.withAnnotations(Nil)
392-
vparam.withMods(mods & (GivenOrImplicit | Erased) | Param)
393-
}
389+
private def toDefParam(vparam: ValDef): ValDef =
390+
vparam.withMods(vparam.rawMods & (GivenOrImplicit | Erased) | Param)
394391

395392
/** The expansion of a class definition. See inline comments for what is involved */
396393
def classDef(cdef: TypeDef)(implicit ctx: Context): Tree = {
@@ -463,7 +460,7 @@ object desugar {
463460
ctx.error(CaseClassMissingNonImplicitParamList(cdef), namePos)
464461
ListOfNil
465462
}
466-
else originalVparamss.nestedMap(toDefParam(_, keepAnnotations = false))
463+
else originalVparamss.nestedMap(toDefParam(_))
467464
val constr = cpy.DefDef(constr1)(tparams = constrTparams, vparamss = constrVparamss)
468465

469466
val (normalizedBody, enumCases, enumCompanionRef) = {
@@ -475,7 +472,7 @@ object desugar {
475472
defDef(
476473
addEvidenceParams(
477474
cpy.DefDef(ddef)(tparams = constrTparams ++ ddef.tparams),
478-
evidenceParams(constr1).map(toDefParam(_, keepAnnotations = false)))))
475+
evidenceParams(constr1).map(toDefParam(_)))))
479476
case stat =>
480477
stat
481478
}
@@ -499,7 +496,7 @@ object desugar {
499496

500497
def anyRef = ref(defn.AnyRefAlias.typeRef)
501498

502-
// Annotations are dropped from the constructor parameters but should be
499+
// Annotations are dropped from the constructor type parameters but should be
503500
// preserved in all derived parameters.
504501
val derivedTparams = {
505502
val impliedTparamsIt = impliedTparams.iterator

0 commit comments

Comments
 (0)