Skip to content

Commit d9023d5

Browse files
committed
Fix #5827: Don't copy protected flag to apply method of case class
1 parent 6bb20b3 commit d9023d5

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,12 @@ object desugar {
629629
(creatorExpr /: widenDefs)((rhs, meth) => Apply(Ident(meth.name), rhs :: Nil))
630630
val applyMeths =
631631
if (mods is Abstract) Nil
632-
else
633-
DefDef(nme.apply, derivedTparams, derivedVparamss, applyResultTpt, widenedCreatorExpr)
634-
.withFlags(Synthetic | constr1.mods.flags & (DefaultParameterized | copiedAccessFlags)) :: widenDefs
632+
else {
633+
val copiedFlagsMask = DefaultParameterized | (copiedAccessFlags & Private)
634+
val app = DefDef(nme.apply, derivedTparams, derivedVparamss, applyResultTpt, widenedCreatorExpr)
635+
.withFlags(Synthetic | constr1.mods.flags & copiedFlagsMask)
636+
app :: widenDefs
637+
}
635638
val unapplyMeth = {
636639
val unapplyParam = makeSyntheticParameter(tpt = classTypeRef)
637640
val unapplyRHS = if (arity == 0) Literal(Constant(true)) else Ident(unapplyParam.name)

tests/pos/i5827.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
case class Foo protected(a: Int)

0 commit comments

Comments
 (0)