Skip to content

jextract: Fix compilation errors in constrained generic extensions#734

Open
sidepelican wants to merge 6 commits intoswiftlang:mainfrom
sidepelican:conditional_extension
Open

jextract: Fix compilation errors in constrained generic extensions#734
sidepelican wants to merge 6 commits intoswiftlang:mainfrom
sidepelican:conditional_extension

Conversation

@sidepelican
Copy link
Copy Markdown
Contributor

This PR addresses compilation errors occurring in the generated "opener" code for certain constrained generic extensions.

  1. Protocol-constrained extensions
extension Foo where Element: SomeProtocol {
    public func something() {} 
}

When an extension has a protocol requirement, the functions were being exported into "opener" code that does not satisfy the protocol constraint, leading to a build failure.

  1. Same-type constraints with type parameters on the RHS
public struct Box<Element> {}
public struct Bait {}

extension Box where Bait == Element {
  public func swappedObserveTheBait() {}
}

In cases like where Bait == Element, the generator was incorrectly exporting functions.
Similar to the protocol case, the opener fails to satisfy the same-type requirement when a type parameter is involved on the right-hand side.

I have updated the Swift2JavaVisitor implementation to correctly identify these problematic constraints.

@sidepelican sidepelican requested a review from ktoso as a code owner May 11, 2026 03:23
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.

1 participant