swiftlang / swiftlang/swift-java
Correctly importing Optional::get() as -> T causes MethodNotFound
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 1.2k
- Forks
- 123
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 16
Description
We are now able to handle generics more properly in wrap-java and now we import Optional as:
@JavaClass("java.util.Optional")
open class JavaOptional<T: AnyJavaObject>: JavaObject {
@JavaMethod
open func get() -> T!
which then crashes
SwiftJava/JavaOptional.swift:2: Fatal error: 'try!' expression unexpectedly raised an error: java.lang.NoSuchMethodError: Ljava/util/Optional;.get()Ljava/lang/String;
so the String bit is coming unexpectedly because Swift sees the reified generic type as "String" and not "some T" therefore the downcall is forming an incorrect signature.
The problem is somewhere in the dynamicJavaMethodCall infra which can't handle the generic properly when forming the downcall signature
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the crash from SwiftJava/JavaOptional.swift, then trace the dynamicJavaMethodCall infrastructure that forms the downcall signature for Optional::get(). Verify how the reified generic return type is represented and ensure the completed behavior no longer requests the String-specific Java method signature or raises NoSuchMethodError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100