通过隐式类的泛型方法重载

Artavazd Balayan 5 generics scala implicit

当我尝试通过隐式类为该类创建扩展并重载现有的通用方法时,它会因编译错误而失败:

error: overloaded method value getAs with alternatives:
  (fieldName: String)String <and>
  (i: Int)String
 cannot be applied to (FooField.type)
       r.getAs[String](FooField)

通过隐式重载正常(非泛型)方法时,效果很好。在Scala 2.12.10上试用。链接到scastie。我想念什么?代码:

trait Row {
    // Two overloads for `getAs[T]`
    def getAs[T](i: Int): T
    def getAs[T](fieldName: String): T

    // Two overloads for `get`
    def get(i: Int): String
    def get(fieldName: String): String
}

trait Field {
    def columnName: String
    def columnDescription: String
}
case object FooField extends Field {
    def columnName: String = "Foo"
  def columnDescription: String = "Foo desc"
}

object Implicits {
  implicit class RowEx(val r: Row) extends AnyVal {
    def getAs[T](field: Field): T = r.getAs[T](field.columnName)
    def get(field: Field): String = {
      println(s"RowEx.get: field")
      r.get(field.columnName)
    }
  }
}

object Main {
  import Implicits._
  // Create some instance of `Row`
  val r = new Row {
    def getAs[T](i: Int): T = i.toString.asInstanceOf[T]
    def getAs[T](fieldName: String): T = fieldName.toString.asInstanceOf[T]
    def get(i: Int): String = i.toString
    def get(fieldName: String): String = fieldName
  }

  def main(args: Array[String]): Unit = {
    // Call extension method => `RowEx.get`
    println(r.get(FooField))

    // Call extension method => `RowEx.get`
    // Won't compile with compilation error:
    /*
    overloaded method value getAs with alternatives:
      (fieldName: String)String 
      (i: Int)String
     cannot be applied to (FooField.type)
    */
    println(r.getAs[String](FooField))
  }
}

打开了一个错误:https : //github.com/scala/bug/issues/11810