Open
Description
Compiler version
3.1.3
Minimized code
trait NotWorking:
def example[K, A, T[X,Y] <: Iterable[(X, Y)]](ab: String): T[K,A] = ???
trait Working:
type M[X,Y] = Iterable[(X, Y)]
def example[K, A, T[X,Y] <: M[X,Y]](ab: String): T[K,A] = ???
// Throws java.lang.reflect.MalformedParameterizedTypeException: Mismatch of count of formal and actual type arguments in constructor of scala.collection.Iterable: 1 formal argument(s) 2 actual argument(s)
classOf[NotWorking].getMethods().map(_.getGenericReturnType())
// Works
classOf[Working].getMethods().map(_.getGenericReturnType())
Output
// No output or an exception thrown
Expectation
I'd expect to be able to obtain generic return type in both cases. I'd not expect observable difference between the two cases.
In the wild - stumbled upon this while trying to make GraalVM native image from an app using zio-json, where JSONEncoder has similar type parameters in keyValueIterator method:
Interestingly the exception is thrown when trying to get the return type of the trait's method, but not when accessing the completed JSONEncoder object's method.
Tested with OpenJDK 17 and OpenJDK 11.