On Mon, 4 Jun 2012 11:10:32 +0200
Adriaan Moors <
adriaa...@epfl.ch> wrote:
> I think we could *always* provide a more helpful message when one of the
> overloaded variants could type check if types were inferred differently.
> Since we're already erroring out, the performance hit may be acceptable.
Thanks for looking at this...
> Your example:
>
> ```
> A.scala:11: error: overloaded method value overloaded with alternatives:
> (special: Special[Boolean])Unit <and>
> (normal: Normal[Boolean])Unit
> cannot be applied to (Normal[Int])
> overloaded[Boolean](new Normal(3))
> ^
> ```
>
> Could be improved to (modulo more error-messagey wording):
>
> ```
> A.scala:11: error: overloaded method value overloaded with alternatives:
> (special: Special[Boolean])Unit <and>
> (normal: Normal[Boolean])Unit
> cannot be applied to (Normal[Int])
> overloaded[Boolean](new Normal(3))
> ^
>
> Note: Normal[Int] was inferred for overloaded's argument.
> However, the closest overloaded variant requires a Normal[Boolean].
> If that's what you meant, the above error becomes:
>
> found : Int(3)
> required: Boolean
> overloaded[Boolean](new Normal(3))
> ^
> ```
A double message is probably more confusing, but perhaps the first section can be dropped. This would be more what I'm aiming for:
Normal[Int] was inferred for overloaded's argument.
However, the closest overloaded variant requires a Normal[Boolean].
found : Int(3)
required: Boolean
overloaded[Boolean](new Normal(3))
^
It implies there is an overload without taking up too much vertical space and preserves the clearer found/required lines. Of course, you've generalized the concept and now have the SIP-worthy "closest overloaded variant".
I thought the patch improved inference as well, so that this compiles:
overloaded[Int => Boolean](new Normal(_ == 0))
but either it never did or something changed in trunk (I wrote the original patch months ago). It is the double penalty of error message and inference that I was trying to overcome, but improving the error message without the need for a special annotation would be great.
-Mark