-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Case class copy and apply inherit access modifiers from constructor
Fixes scala/bug#7884
- Loading branch information
Showing
9 changed files
with
170 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
caseclass_private_constructor.scala:4: error: method apply in object A cannot be accessed in object A | ||
error after rewriting to A.<apply: error> | ||
possible cause: maybe a wrong Dynamic method signature? | ||
def a1: A = A(1) // error: apply is private | ||
^ | ||
caseclass_private_constructor.scala:5: error: method copy in class A cannot be accessed in A | ||
def a2: A = a1.copy(2) // error: copy is private | ||
^ | ||
caseclass_private_constructor.scala:10: error: method apply in object B cannot be accessed in object B | ||
error after rewriting to B.<apply: error> | ||
possible cause: maybe a wrong Dynamic method signature? | ||
def b1: B = B(1) // error: apply is private | ||
^ | ||
caseclass_private_constructor.scala:11: error: method copy in class B cannot be accessed in B | ||
def b2: B = b1.copy(2) // error: copy is private | ||
^ | ||
caseclass_private_constructor.scala:22: error: method apply in object C cannot be accessed in object qualified_private.C | ||
error after rewriting to qualified_private.C.<apply: error> | ||
possible cause: maybe a wrong Dynamic method signature? | ||
def c1: C = C(1) // error: apply is private | ||
^ | ||
caseclass_private_constructor.scala:23: error: method copy in class C cannot be accessed in qualified_private.C | ||
def c2: C = c1.copy(2) // error: copy is private | ||
^ | ||
caseclass_private_constructor.scala:25: error: method apply in object D cannot be accessed in object qualified_private.D | ||
error after rewriting to qualified_private.D.<apply: error> | ||
possible cause: maybe a wrong Dynamic method signature? | ||
def d1: D = D(1) // error: apply is private | ||
^ | ||
caseclass_private_constructor.scala:26: error: method copy in class D cannot be accessed in qualified_private.D | ||
def d2: D = d1.copy(2) // error: copy is private | ||
^ | ||
caseclass_private_constructor.scala:32: error: method copy in class E cannot be accessed in E | ||
Access to protected method copy not permitted because | ||
enclosing object ETest is not a subclass of | ||
class E where target is defined | ||
def e2: E = e2.copy(2) // error: copy is protected | ||
^ | ||
caseclass_private_constructor.scala:41: error: method copy in class F cannot be accessed in qualified_protected.F | ||
Access to protected method copy not permitted because | ||
enclosing object QProtTest is not a subclass of | ||
class F in object qualified_protected where target is defined | ||
def f2: F = f2.copy(2) // error: copy is protected | ||
^ | ||
10 errors found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
case class A private (i: Int) | ||
object A | ||
object ATest { | ||
def a1: A = A(1) // error: apply is private | ||
def a2: A = a1.copy(2) // error: copy is private | ||
} | ||
|
||
case class B private (i: Int) // no user-defined companion object, should compile | ||
object BTest { | ||
def b1: B = B(1) // error: apply is private | ||
def b2: B = b1.copy(2) // error: copy is private | ||
} | ||
|
||
object qualified_private { | ||
case class C private[qualified_private] (i: Int) | ||
object C | ||
|
||
case class D private[qualified_private] (i: Int) // no user-defined companion object, should compile | ||
} | ||
object QPrivTest { | ||
import qualified_private._ | ||
def c1: C = C(1) // error: apply is private | ||
def c2: C = c1.copy(2) // error: copy is private | ||
|
||
def d1: D = D(1) // error: apply is private | ||
def d2: D = d1.copy(2) // error: copy is private | ||
} | ||
|
||
case class E protected (i: Int) | ||
object ETest { | ||
def e1: E = E(1) | ||
def e2: E = e2.copy(2) // error: copy is protected | ||
} | ||
|
||
object qualified_protected { | ||
case class F protected[qualified_protected] (i: Int) | ||
} | ||
object QProtTest { | ||
import qualified_protected._ | ||
def f1: F = F(1) | ||
def f2: F = f2.copy(2) // error: copy is protected | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
case class A private (i: Int) | ||
object A { | ||
def a = A(1).copy(2) // apply and copy are accessible in companion | ||
} | ||
|
||
case class B private (i: Int) { // no user-defined companion object, should compile | ||
def b = B(1).copy(2) // apply and copy are accessible | ||
} | ||
|
||
object qualified_private { | ||
case class A private[qualified_private] (i: Int) | ||
object A { | ||
def a = A(1).copy(2) // apply and copy are accessible in companion | ||
} | ||
|
||
def a = A(1).copy(2) // apply and copy are accessible in qualified_private object | ||
|
||
case class B private[qualified_private] (i: Int) { // no user-defined companion object, should compile | ||
def b = B(1).copy(2) // apply and copy are accessible | ||
} | ||
|
||
def b = B(1).copy(2) // apply and copy are accessible in qualified_private object | ||
} | ||
|
||
case class C protected (i: Int) | ||
class CSub extends C(1) { | ||
def c = copy(2) // copy is accessible in subclass | ||
} | ||
object CTest { | ||
def c = C(1) // apply is public | ||
} | ||
|
||
object qualified_protected { | ||
case class C protected[qualified_protected] (i: Int) | ||
class CSub extends C(1) { | ||
def c = copy(2) // copy is accessible in subclass | ||
} | ||
object CTest { | ||
def c = C(1) // apply is public | ||
def checkExtendsFunction: Int => C = C // companion extends (Int => C) | ||
} | ||
|
||
def c = C(1).copy(2) | ||
} | ||
object CQualifiedTest { | ||
def c = qualified_protected.C(1) // apply is public | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
class C { case class Foo private (x: Int); Foo.apply(0) } | ||
class C { case class Foo protected (x: Int); Foo.apply(0) } | ||
|
||
object Test { | ||
def test(c: C) = {import c.Foo; Foo.apply(0)} | ||
def main(args: Array[String]): Unit = { | ||
test(new C) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters