Zero-arg pattern matches when one arg expected

Viewed 97

Given this definition in Scala:

class Foo(val n: Int)

object Foo {
  def unapply(foo: Foo): Option[Int] = Some(foo.n)
}

This expression compiles and returns ok:

new Foo(1) match {
  case Foo() => "ok"
}
  1. Why does this even compile? I would expect that an extractor with Option[T] implies matching patterns with exactly one argument only.
  2. What does the pattern Foo() mean here? Is it equivalent to Foo(_)?

In other words, what is the language rule that enables the experienced behavior.

2 Answers
Related