Skip to content

jextract: skip prefix and postfix operators by their modifier - #950

Open
piercifani wants to merge 1 commit into
swiftlang:mainfrom
piercifani:jextract-prefix-operators
Open

piercifani wants to merge 1 commit into
swiftlang:mainfrom
piercifani:jextract-prefix-operators

Conversation

@piercifani

Copy link
Copy Markdown

JavaExtractDecider is meant to skip prefix and postfix operators, which have no Java mapping. It checked the declaration's name token for .prefixOperator or .postfixOperator, but in a declaration the operator name is always lexed as a binary operator:

public struct Number {
  public static prefix func - (value: Number) -> Number { value }
}

So - here was extracted as a binary operator. In JNI mode, generating the Swift thunks then stopped jextract:

JNISwift2JavaGenerator+SwiftThunkPrinting.swift:712: Fatal error: Binary operator must have exactly 2 arguments

The check now looks for the prefix or postfix modifier.

Testing

  • Two new JNIOperatorsTests, one checking the Java bindings and one the Swift thunks, with a prefix - and a postfix ++ next to a binary +. On main they crash with the fatal error above.
  • swift test passes.

🤖 Generated with Claude Code

JavaExtractDecider meant to skip prefix and postfix operators by checking
the name token for .prefixOperator or .postfixOperator. In a declaration
such as `public static prefix func - (value: Number) -> Number` the name is
lexed as a binary operator, and only the `prefix` modifier tells it apart.
So the operator was extracted as a binary operator, and in JNI mode the
Swift thunk printer stopped with `Binary operator must have exactly 2
arguments`. Check the modifiers instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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