From d9023d50f15bd7859929952fe3e428e81d91020b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 1 Feb 2019 09:41:23 +0100 Subject: [PATCH 1/2] Fix #5827: Don't copy protected flag to apply method of case class --- compiler/src/dotty/tools/dotc/ast/Desugar.scala | 9 ++++++--- tests/pos/i5827.scala | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i5827.scala diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 695795c878db..961d63814c7b 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -629,9 +629,12 @@ object desugar { (creatorExpr /: widenDefs)((rhs, meth) => Apply(Ident(meth.name), rhs :: Nil)) val applyMeths = if (mods is Abstract) Nil - else - DefDef(nme.apply, derivedTparams, derivedVparamss, applyResultTpt, widenedCreatorExpr) - .withFlags(Synthetic | constr1.mods.flags & (DefaultParameterized | copiedAccessFlags)) :: widenDefs + else { + val copiedFlagsMask = DefaultParameterized | (copiedAccessFlags & Private) + val app = DefDef(nme.apply, derivedTparams, derivedVparamss, applyResultTpt, widenedCreatorExpr) + .withFlags(Synthetic | constr1.mods.flags & copiedFlagsMask) + app :: widenDefs + } val unapplyMeth = { val unapplyParam = makeSyntheticParameter(tpt = classTypeRef) val unapplyRHS = if (arity == 0) Literal(Constant(true)) else Ident(unapplyParam.name) diff --git a/tests/pos/i5827.scala b/tests/pos/i5827.scala new file mode 100644 index 000000000000..e5fdbe7845a6 --- /dev/null +++ b/tests/pos/i5827.scala @@ -0,0 +1 @@ +case class Foo protected(a: Int) \ No newline at end of file From 4ba1cf6a326a4555c68508e62014d9de620e277b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 1 Feb 2019 13:16:08 +0100 Subject: [PATCH 2/2] Throw in a private constructor, just to make sure that works --- tests/pos/i5827.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/pos/i5827.scala b/tests/pos/i5827.scala index e5fdbe7845a6..83f7571ec4b8 100644 --- a/tests/pos/i5827.scala +++ b/tests/pos/i5827.scala @@ -1 +1,3 @@ -case class Foo protected(a: Int) \ No newline at end of file +case class Foo protected(a: Int) + +case class Bar private(a: Int) \ No newline at end of file