Skip to content

Commit 227928c

Browse files
committed
Protected case class constructor -> private apply
1 parent 847cce2 commit 227928c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,8 @@ object desugar {
706706
else {
707707
val copiedFlagsMask = copiedAccessFlags & Private
708708
val appMods = {
709-
val mods = Modifiers(Synthetic | constr1.mods.flags & copiedFlagsMask)
709+
val protectedToPrivate = if constr1.mods.is(Protected) then Protected | Private else EmptyFlags
710+
val mods = Modifiers((Synthetic | constr1.mods.flags ^ protectedToPrivate) & copiedFlagsMask)
710711
if (restrictedAccess) mods.withPrivateWithin(constr1.mods.privateWithin)
711712
else mods
712713
}

tests/neg/i14187.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sealed case class Foo protected (i: Int, j: Int)
2+
3+
final class Bar(n: Int) extends Foo(n, n)
4+
5+
class Other:
6+
def foo = Foo(1, 2) // error
7+
def foo2 = Foo.apply(1, 2) // error

0 commit comments

Comments
 (0)