wrap-java: Supporting return type erasure bounds#626
Conversation
Co-authored-by: Konrad `ktoso` Malawski <konrad.malawski@project13.pl>
Sources/SwiftJava/Macros.swift
Outdated
| typeErasedResult: String? = nil | ||
| ) = #externalMacro(module: "SwiftJavaMacros", type: "JavaMethodMacro") | ||
|
|
||
| @attached(body) |
There was a problem hiding this comment.
Could need some docs why this one does require the erased result types and then do a See: to the "main one" for more docs.
Sources/SwiftJava/Macros.swift
Outdated
| ) = #externalMacro(module: "SwiftJavaMacros", type: "JavaMethodMacro") | ||
|
|
||
| @attached(body) | ||
| public macro JavaMethod<Result: JavaValue>( |
There was a problem hiding this comment.
Actually... how about we keep ONE macro, and diagnose from inside the macro if typeErasedResultBound was provided but the typeErasedResult wasn't? Since that's what you're trying to enforce here. I'd like to avoid having many overloads here in the sources so that docs are easy to find
ktoso
left a comment
There was a problem hiding this comment.
Very nice, one nitpick about the new macro declaration, best if we could keep the single declaration, wdyt?
|
I was able to unify the macro definitions. |
|
Very nice, LGTM; only nitpickt that the docs were not showing a wildcard, a wildcard is |
This PR is part of the improvements for #599.
Calling
getGenericDeclaration()on a generatedjava.lang.reflect.TypeVariablecurrently results in a runtime crash:This is because the JNI method lookup is searching for a signature returning
Object, whereas the actual erased signature in Java returnsGenericDeclaration(the upper bound of the type parameterD).Currently, the
@JavaMethodmacro expands usingJavaObject?.selfas theresultTypefor the erased generic return type.Since the macro cannot infer the original Java bounds from the Swift method signature alone, it defaults to
Object.I have introduced a new macro argument,
typeErasedResultBound, to explicitly provide the bound type.With this change, we can specify the correct type for JNI method resolution: