wrap-java: Update subtyping logic for generic method overrides#618
Open
sidepelican wants to merge 4 commits intoswiftlang:mainfrom
Open
wrap-java: Update subtyping logic for generic method overrides#618sidepelican wants to merge 4 commits intoswiftlang:mainfrom
sidepelican wants to merge 4 commits intoswiftlang:mainfrom
Conversation
sidepelican
commented
Mar 13, 2026
| } | ||
|
|
||
| var methodTypeVars = method.getTypeParameters() | ||
| var methodTypeVars = method.getTypeParameters() as [TypeVariable<JavaLangReflect.Method>?] |
Contributor
Author
There was a problem hiding this comment.
Unfortunately, The override being treated as overload, explicit type annotations are now required. I believe this is unavoidable.
Collaborator
There was a problem hiding this comment.
There's probably no great way to avoid this... Unless we suffix the methods in the subclass? It might be an inherent incompatibility of how swift and java do overrides though
Open to sneaky ideas, maybe @DougGregor might have some?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is likely the final part of the improvements for #599.
In Java,
Executabledefines:Class<?> getDeclaringClass()Constructoroverrides it as:Class<T> getDeclaringClass()Currently,
wrap-javaidentifies these as the same method signature and adds theoverridekeyword in Swift.However, since Swift does not recognize a subtype relationship about them(
JavaClass<JavaObject>vsJavaClass<T>), it results in the following error:To resolve this, I have updated the type-checking logic to be more strict:
Type.isEqualTo(_:), resolved an issue whereClass<?>andClass<T>were incorrectly treated as identical types.adjustToJavaBoundsType.isEqualToOrSubtypeOf(_:), changed the logic so that types with different generic arguments are no longer considered to have a subtype relationship.