Skip to content

Skip static requirements in protocols#553

Open
sidepelican wants to merge 2 commits intoswiftlang:mainfrom
sidepelican:protocol_static
Open

Skip static requirements in protocols#553
sidepelican wants to merge 2 commits intoswiftlang:mainfrom
sidepelican:protocol_static

Conversation

@sidepelican
Copy link
Contributor

Currently, when generating Java code from a Swift protocol (JNI only), static requirements are mapped directly to static methods in a Java interface.
However, unlike Swift protocols, Java interfaces do not support 'static requirements'. This leads to the following compilation errors:

/Users/iceman/github/swift-java/Samples/SwiftJavaExtractJNISampleApp/.build/plugins/outputs/swiftjavaextractjnisampleapp/MySwiftLibrary/destination/JExtractSwiftPlugin/src/generated/java/com/example/swift/ProtocolWithStatic.java:23: error: missing method body, or declare abstract
  public static long myFunc();
                     ^
/Users/iceman/github/swift-java/Samples/SwiftJavaExtractJNISampleApp/.build/plugins/outputs/swiftjavaextractjnisampleapp/MySwiftLibrary/destination/JExtractSwiftPlugin/src/generated/java/com/example/swift/ProtocolWithStatic.java:35: error: missing method body, or declare abstract
  public static long getValue();
                     ^

While there might be a design pattern to introduce 'static requirements' in Java, this feels like a complex change with many points of contention that would require significant time.

To ensure the generated code is compilable, this PR updates the generator to ignore them.

@sidepelican sidepelican requested a review from ktoso as a code owner February 6, 2026 06:20
Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm but please add a note to the features list that this isn't supported

@sidepelican
Copy link
Contributor Author

Actually, I realized there is a slight gap in this implementation.
I missed the case where JavaInterfaceProtocolWrapper is generated.

JavaInterfaceProtocolWrapper cannot be generated when there are static requirements, we will need to skip it in those cases as well.

func generate(for type: ImportedNominalType) throws -> JavaInterfaceSwiftWrapper {

That said, this PR still provides an improvement as-is.
We could merge this first, and I can address the remaining JavaInterfaceProtocolWrapper issue in a separate PR.

@ktoso
Copy link
Collaborator

ktoso commented Feb 7, 2026

That's fine, let's merge this and follow up then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants