Observe the following code
trait Example {
type O
def apply(o: O)
def f(o: O) = this.apply(o)
}
which compiles fine in Scala. I would expect that I can leave out apply as usual, writing def f(o: O) = this(o). However, this results in the exciting error message
type mismatch; found : o.type (with underlying type Example.this.O)
required: _31.O where val _31: Example
possible cause: missing arguments for method or constructor
Can anyone explain to me what’s going on?
The accepted answer is incorrect. You can infer what the actual problem is from the fact that this compiles fine:
this(…) only represents a call to a constructor when the call site is an auxiliary constructor. The remainder of the time it is a call to apply, just as you imagined.