Invocation of static generic method of generic class causes "Illegal type in constant pool"
Trying to invoke the static generic method
Map.<K,V>of(K k1, V v1, K k2, V v2)
produces an "Illegal type in constant pool" error during the lambda class generation.
Below the test case I am using:
@Test
void canInvokeGenericStaticMethodOfGenericClass() {
final var interfaceType = Type.of(Supplier.class).makeGenericType(Types.Map.makeGenericType(Types.String, Types.Integer));
// Map.of(K k1, V v1, K k2, V v2)
final var mapOfMethod =
Types.Map.getMethod("of", Types.Object, Types.Object, Types.Object, Types.Object).makeGenericMethod(Types.String, Types.Integer);
final var invoke =
Expression.call(
mapOfMethod,
new ExpressionList<>(Expression.constant("k1"), Expression.constant(22), Expression.constant("k2"), Expression.constant(109))
);
final var lambda = Expression.lambda(interfaceType, invoke);
//noinspection unchecked
final var delegate = (Supplier<Map<String, Integer>>) lambda.compile();
final var map = delegate.get();
assertNotNull(map);
assertEquals(map.get("key2"), 109);
}
Attached the generated class (zipped). lambda_mapOf.zip
I suspect this is due to Procyon emitting classes in Java 5 format, which doesn't support static interface methods. Emitting newer classfiles is, unfortunately, quite an undertaking.
Have you considered migrating the runtime code generation part to ASM, or maybe make the code generation classes pluggable, so that it is possible to provide a different implementation of TypeBuilder (or emitter)?
I use Procyon mainly for the reflection and expressions features (which are great), the runtime code generation is the cherry on top, but I wouldn't mind if it was delegated to an external library.