Skip to content

Commit 09e1d88

Browse files
committed
Copy full modifiers to companions
1 parent 859629f commit 09e1d88

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ object desugar {
228228
val tparam = cpy.TypeDef(tdef)(name = tdef.name.expandedName(ctx.owner))
229229
.withMods(tdef.mods &~ PrivateLocal | ExpandedName)
230230
val alias = cpy.TypeDef(tdef)(rhs = refOfDef(tparam), tparams = Nil)
231-
.withFlags(PrivateLocalParamAccessor | Synthetic | tdef.mods.flags & VarianceFlags)
231+
.withMods(tdef.mods & VarianceFlags | PrivateLocalParamAccessor | Synthetic)
232232
Thicket(tparam, alias)
233233
}
234234
else tdef
@@ -237,15 +237,15 @@ object desugar {
237237
@sharable private val synthetic = Modifiers(Synthetic)
238238

239239
private def toDefParam(tparam: TypeDef): TypeDef =
240-
tparam.withFlags(Param)
240+
tparam.withMods(tparam.rawMods & EmptyFlags | Param)
241241
private def toDefParam(vparam: ValDef): ValDef =
242-
vparam.withFlags(Param | vparam.rawMods.flags & Implicit)
242+
vparam.withMods(vparam.rawMods & Implicit | Param)
243243

244244
/** The expansion of a class definition. See inline comments for what is involved */
245245
def classDef(cdef: TypeDef)(implicit ctx: Context): Tree = {
246246
val TypeDef(name, impl @ Template(constr0, parents, self, _)) = cdef
247247
val mods = cdef.mods
248-
val accessFlags = (mods.flags & AccessFlags).toCommonFlags
248+
val companionMods = mods.withFlags((mods.flags & AccessFlags).toCommonFlags)
249249

250250
val (constr1, defaultGetters) = defDef(constr0, isPrimaryConstructor = true) match {
251251
case meth: DefDef => (meth, Nil)
@@ -364,7 +364,7 @@ object desugar {
364364
moduleDef(
365365
ModuleDef(
366366
name.toTermName, Template(emptyConstructor, parentTpt :: Nil, EmptyValDef, defs))
367-
.withFlags(Synthetic | accessFlags))
367+
.withMods(companionMods | Synthetic))
368368
.withPos(cdef.pos).toList
369369

370370
// The companion object definitions, if a companion is needed, Nil otherwise.
@@ -421,10 +421,9 @@ object desugar {
421421
// implicit wrapper is typechecked in same scope as constructor, so
422422
// we can reuse the constructor parameters; no derived params are needed.
423423
DefDef(name.toTermName, constrTparams, constrVparamss, classTypeRef, creatorExpr)
424-
.withFlags(Synthetic | Implicit | accessFlags)
424+
.withMods(companionMods | Synthetic | Implicit)
425425
.withPos(cdef.pos) :: Nil
426426

427-
428427
val self1 = {
429428
val selfType = if (self.tpt.isEmpty) classTypeRef else self.tpt
430429
if (self.isEmpty) self

0 commit comments

Comments
 (0)