Skip to content

wrap-java: qualify Optional convenience method calls with self - #8

Merged
teamhimeh merged 1 commit into
qoncept-forkfrom
codex/fix-wrap-java-optional-method-calls
Oct 23, 2026
Merged

teamhimeh merged 1 commit into
qoncept-forkfrom
codex/fix-wrap-java-optional-method-calls

Conversation

@teamhimeh

@teamhimeh teamhimeh commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Optional convenience methods generated by wrap-java invoke the original method without a receiver. A parameter can therefore shadow that method and make the generated Swift fail to compile.

For example, this Java declaration:

public OptionalLong arg0(OptionalLong value) { return value; }

produces a Swift convenience method whose argument is also named arg0:

open func arg0Optional(_ arg0: Int64?) -> Int64? {
  Optional(javaOptional: arg0(arg0.toJavaOptional()))
}

The body attempts to call the Optional argument as a function. With this change, it explicitly calls the original method:

open func arg0Optional(_ arg0: Int64?) -> Int64? {
  Optional(javaOptional: self.arg0(arg0.toJavaOptional()))
}

Changes

  • Qualify calls from Optional convenience methods with self.
  • Preserve argument conversion, result conversion, and checked-exception handling.
  • Add a regression using compiled Java source that covers instance and static methods, checked exceptions, Optional results, and methods whose only Optional value is an argument.

Validation

  • Confirmed the new regression fails against the unmodified generator and passes with this change.
  • swift test --disable-experimental-prebuilts --disable-sandbox: full Swift test suite passed.
  • swift-format and git diff --check passed.

Tested with Apple Swift 6.4 and JetBrains Runtime 25 on macOS.

@teamhimeh
teamhimeh force-pushed the codex/fix-wrap-java-optional-method-calls branch from 09b806f to 6e80f20 Compare October 23, 2026 07:58
@teamhimeh
teamhimeh merged commit e48618b into qoncept-fork Oct 23, 2026
32 of 42 checks passed
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