Hi all
As far as I can see from usage and -print REPL output, the generated companion object for a case class with N parameters is a subclass of FunctionN (2.11.6 REPL):
scala> :set -print
scala> case class Foo()
[[syntax trees at end of cleanup]] // <console>
...
<synthetic> object iw$Foo extends scala.runtime.AbstractFunction0 with Serializable {
scala> case class Bar(n: Int)
[[syntax trees at end of cleanup]] // <console>
...
<synthetic> object iw$Bar extends scala.runtime.AbstractFunction1 with Serializable {
scala> List(1, 2) map Bar
res0: List[Bar] = List(Bar(1), Bar(2))
SLS 5.3.2 [1] does not, as far as I can make out, say anything about this. The extractor object as defined there behaves differently from the one generate by the compiler:
scala> :paste
// Entering paste mode (ctrl-D to finish)
// not a case class; define the extractor as described in SLS explicitly
class Baz(n: Int)
object Baz {
def apply(n: Int): Baz = new Baz(n)
// other stuff
}
// Exiting paste mode, now interpreting.
defined class Baz
defined object Baz
scala> List(1, 2) map Baz
<console>:12: error: type mismatch;
found : Baz.type
required: Int => ?
List(1, 2) map Baz
^
Is this a misreading/-understanding? If not, would this be considered a compiler bug, a spec omission or something else?
Regards
ap