Skip to content

jextract: Support prefix/postfix operators properly - #966

Open
ktoso wants to merge 2 commits into
swiftlang:mainfrom
ktoso:ktoso/jextract-prefix-postfix-operators
Open

ktoso wants to merge 2 commits into
swiftlang:mainfrom
ktoso:ktoso/jextract-prefix-postfix-operators

Conversation

@ktoso

@ktoso ktoso commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Instead of skipping them like #950 proposed, let's handle them properly.

Depends on swiftlang/swift-binding-generator-core#7

Prefix and postfix operators declared in a type are now extracted as
static Java methods, named like binary operators: `prefix func -` is
`minus(value)` and `postfix func ++` is `plusPlus(value)`.

- JNI thunks call them without whitespace between operator and operand,
  `(-(x))` and `((x)++)`. With whitespace, Swift parses neither as a
  prefix or postfix operator.
- `JavaIdentifierFactory` grouped operators by their Swift name but looked
  up conflicts by their Java name, so it never found operator conflicts.
  A prefix and a postfix form of one operator (`prefix func ...` and
  `postfix func ...`) now get a `Prefix` or `Postfix` suffix.
- `JavaExtractDecider` skips only operators declared at file scope.

Requires swift-binding-generator-core to classify operators by their
`prefix` and `postfix` modifiers, rather than by the token kind of the
name, which depends on whitespace.
Operators declared at file scope are now extracted as static methods on
the module's Java class, named like operators declared in a type:
`func * (left: Int64, right: OperatorScore)` is
`MySwiftLibrary.times(2, score, arena)`.

Requires swift-binding-generator-core to classify file-scope operator
funcs as operators.
@ktoso ktoso changed the title Support prefix/postfix operators properly jextract: Support prefix/postfix operators properly Nov 16, 2026
@ktoso ktoso closed this Nov 16, 2026
@ktoso ktoso reopened this Nov 16, 2026
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