diff --git a/docs/incompatibilities/other-changed-features.md b/docs/incompatibilities/other-changed-features.md index 5e053fe..110b54d 100644 --- a/docs/incompatibilities/other-changed-features.md +++ b/docs/incompatibilities/other-changed-features.md @@ -26,3 +26,6 @@ title: Other Changed Features ```scala mdoc:file:incompat-30/wildcard-argument/README.md ``` + +```scala mdoc:file:incompat-30/case-class-companion/README.md +``` diff --git a/docs/incompatibilities/table.md b/docs/incompatibilities/table.md index b22d0bb..3972532 100644 --- a/docs/incompatibilities/table.md +++ b/docs/incompatibilities/table.md @@ -83,7 +83,7 @@ Some proven features are simplified or restricted to make the language easier an |[Non-private constructor in private class](other-changed-features.md#non-private-constructor-in-private-class)||warning||| |[Reflective call](other-changed-features.md#reflective-call)||||Type inference problem| |[Wildcard type argument](other-changed-features.md#wildcard-type-argument)||||| - +|[Case class companion](other-changed-features.md#case-class-companion)||||| ## Implicit Resolution diff --git a/incompat-30/case-class-companion/README.md b/incompat-30/case-class-companion/README.md new file mode 100644 index 0000000..7625e1a --- /dev/null +++ b/incompat-30/case-class-companion/README.md @@ -0,0 +1,29 @@ +## Case class companion + +The companion object of a case class does not extend any of the `Function{0-23}` traits anymore. +In particular, it does not inherit their methods: `tupled`, `curried`, `andThen`, `compose`... + +For instance, the following lines of code are invalid. + +```scala +case class Foo(x: Int, b: Boolean) + +Foo.curried(1)(true) +Foo.tupled((2, false)) +``` + +A cross-compiling solution is to explicitly eta-expand the method `Foo.apply`. + +```scala +(Foo.apply _).curried(1)(true) +(Foo.apply _).tupled((2, false)) +``` + +Or, for performance reason, you can introduce an intermediate function value. + +```scala +val fooCtr: (Int, Boolean) => Foo = (x, b) => Foo(x, b) + +fooCtr.curried(1)(true) +fooCtr.tupled((2, false)) +``` diff --git a/incompat-30/case-class-companion/src/main/scala-2.13/case-class-companion.scala b/incompat-30/case-class-companion/src/main/scala-2.13/case-class-companion.scala new file mode 100644 index 0000000..fa3747f --- /dev/null +++ b/incompat-30/case-class-companion/src/main/scala-2.13/case-class-companion.scala @@ -0,0 +1,8 @@ +package foo + +case class Foo(x: Int, b: Boolean) + +object Bar { + val f1 = Foo.curried(1)(true) + val f2 = Foo.tupled((2, false)) +} diff --git a/incompat-30/case-class-companion/src/main/scala/case-class-companion.scala b/incompat-30/case-class-companion/src/main/scala/case-class-companion.scala new file mode 100644 index 0000000..fa7e2df --- /dev/null +++ b/incompat-30/case-class-companion/src/main/scala/case-class-companion.scala @@ -0,0 +1,13 @@ +package foo + +case class Foo(x: Int, b: Boolean) + +object Bar { + val f1 = (Foo.apply _).curried(1)(true) + val f2 = (Foo.apply _).tupled((1, true)) + + val fooCtr: (Int, Boolean) => Foo = (x, b) => Foo(x, b) + + val f1Bis = fooCtr.curried(1)(true) + val f2Bis = fooCtr.tupled((2, false)) +} diff --git a/incompat.sbt b/incompat.sbt index df396d2..260365b 100644 --- a/incompat.sbt +++ b/incompat.sbt @@ -152,7 +152,8 @@ lazy val otherIncompats = Seq[ProjectReference]( ambiguousConversion, implicitView, typeOfImplicitDef, - viewBound + viewBound, + caseClassCompanion ) // Syntactic incompatibilities @@ -172,6 +173,7 @@ lazy val existentialType = project.in(file("incompat-30/existential-type")).sett lazy val wildcardArgument = project.in(file("incompat-30/wildcard-argument")).settings(incompat30Settings) lazy val explicitCallToUnapply = project.in(file("incompat-30/explicit-call-to-unapply")).settings(incompat30Settings) lazy val reflectiveCall = project.in(file("incompat-30/reflective-call")).settings(incompat30Settings) +lazy val caseClassCompanion = project.in(file("incompat-30/case-class-companion")).settings(incompat30Settings) // Contextual abstraction incompatibilities lazy val ambiguousConversion =