I'm playing with Scala reflection and ScalaTest. I've a method defined as follows in an object Ch2
: def isSorted[A](as: Array[A], ordered: (A, A) => Boolean): Boolean
The following test fails as described in the comment:
"Method isSorted" should "return true for a sorted array" in {
val methods =
Table(
("method"),
("isSorted")
)
val m = ru.runtimeMirror(getClass.getClassLoader)
val mod = ru.typeOf[Ch2.type].termSymbol.asModule
val mm = m.reflectModule(mod)
val obj = mm.instance
val im = m.reflect(obj)
forAll(methods) { (m: String) =>
val isSortedMethod = ru.typeOf[Ch2.type].decl(ru.TermName(m)).asMethod
val isSorted = im.reflectMethod(isSortedMethod)
// Fails at runtime with 'missing parameter type for expanded function'
isSorted(Array(1, 2, 3, 4), Ordering[Int].lt(_, _))
}
}
Aucun commentaire:
Enregistrer un commentaire