2

Scala's overloaded method resolution seems strange here:

abstract class Parent { type T }
class Child extends Parent { type T = Int }

def f[T <: Parent](a: Array[T]): Array[T#T] = null
def f[T](a: T): Array[T] = null

val s = f(Array(new Child))                   // OK; calls the first f
val t: Array[Child#T] = f(Array(new Child))   // type mismatch; tries to apply the second f

Although s has the same type as t's, s is successfully evaluated using the first f but just giving a type hint makes the compiler try the second f and fail requiring Int as its argument. I ended up avoiding use of method overloading but just out of curiosity, can anybody inform me as to what's wrong here?

K J
  • 4,505
  • 6
  • 27
  • 45
  • This seems like a bug to me. You should ask this question on the scala mailing list. – drexin Jan 19 '13 at 19:43
  • 3
    You should read this post on why to avoid method overloading: http://stackoverflow.com/questions/2510108/why-avoid-method-overloading Specifically this article mentioned in the post demonstrates your issue: http://gbracha.blogspot.com/2009/09/systemic-overload.html – Noah Jan 19 '13 at 19:59

0 Answers0