summaryrefslogtreecommitdiff
path: root/test/files/pos/userdefined_apply.scala
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan@lightbend.com>2017-04-10 10:12:01 -0700
committerGitHub <noreply@github.com>2017-04-10 10:12:01 -0700
commit715c88e9b74d1b4d1d0c4da9d0cc8f1b740e2dd3 (patch)
treeb851e7bfd0dd821b39eae1ac25ca053362bee72d /test/files/pos/userdefined_apply.scala
parent2ba0530218daa170df5f1d25f7b39ab8cb8d0cf7 (diff)
parentade53a123c1edce12db442ee74b636d130e7e0f2 (diff)
downloadscala-715c88e9b74d1b4d1d0c4da9d0cc8f1b740e2dd3.tar.gz
scala-715c88e9b74d1b4d1d0c4da9d0cc8f1b740e2dd3.tar.bz2
scala-715c88e9b74d1b4d1d0c4da9d0cc8f1b740e2dd3.zip
Merge pull request #5816 from adriaanm/userdefined-apply-212
Allow user-defined `[un]apply` in case companion
Diffstat (limited to 'test/files/pos/userdefined_apply.scala')
-rw-r--r--test/files/pos/userdefined_apply.scala54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/files/pos/userdefined_apply.scala b/test/files/pos/userdefined_apply.scala
new file mode 100644
index 0000000000..e29f9f5141
--- /dev/null
+++ b/test/files/pos/userdefined_apply.scala
@@ -0,0 +1,54 @@
+// NOTE: the companion inherits a public apply method from Function1!
+case class NeedsCompanion private (x: Int)
+
+object ClashNoSig { // ok
+ private def apply(x: Int) = if (x > 0) new ClashNoSig(x) else ???
+}
+case class ClashNoSig private (x: Int)
+
+
+object Clash {
+ private def apply(x: Int) = if (x > 0) new Clash(x) else ???
+}
+case class Clash private (x: Int)
+
+object ClashSig {
+ private def apply(x: Int): ClashSig = if (x > 0) new ClashSig(x) else ???
+}
+case class ClashSig private (x: Int)
+
+object ClashOverload {
+ private def apply(x: Int): ClashOverload = if (x > 0) new ClashOverload(x) else apply("")
+ def apply(x: String): ClashOverload = ???
+}
+case class ClashOverload private (x: Int)
+
+object NoClashSig {
+ private def apply(x: Boolean): NoClashSig = if (x) NoClashSig(1) else ???
+}
+case class NoClashSig private (x: Int)
+
+object NoClashOverload {
+ // needs full sig
+ private def apply(x: Boolean): NoClashOverload = if (x) NoClashOverload(1) else apply("")
+ def apply(x: String): NoClashOverload = ???
+}
+case class NoClashOverload private (x: Int)
+
+
+
+class BaseNCP[T] {
+ // error: overloaded method apply needs result type
+ def apply(x: T): NoClashPoly = if (???) NoClashPoly(1) else ???
+}
+
+object NoClashPoly extends BaseNCP[Boolean]
+case class NoClashPoly private(x: Int)
+
+
+class BaseCP[T] {
+ // error: overloaded method apply needs result type
+ def apply(x: T): ClashPoly = if (???) ClashPoly(1) else ???
+}
+object ClashPoly extends BaseCP[Int]
+case class ClashPoly private(x: Int)