Skip to content

JNI: avoid enum case record names that collide with enclosing types - #7

Merged
teamhimeh merged 1 commit into
qoncept-forkfrom
codex/fix-jni-enum-case-name-collisions
Oct 23, 2026
Merged

teamhimeh merged 1 commit into
qoncept-forkfrom
codex/fix-jni-enum-case-name-collisions

Conversation

@teamhimeh

@teamhimeh teamhimeh commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

JNI enum extraction capitalizes each Swift case name to generate a nested Java record. That record can have the same name as its enum, another enclosing type, or the generated Case interface. Java rejects these declarations because a nested type cannot share an enclosing type's name.

For example:

public enum Message {
  case message(Int64)
}

Previously, this generated a record named Message inside Message.Case, which fails Java compilation. With this change, the record is named MessageCase, and its payload accessor is consistently named getAsMessageCase():

try (var arena = SwiftArena.ofConfined()) {
    Message value = Message.message(42, arena);
    Message.Case.MessageCase payload = value.getAsMessageCase().orElseThrow();
    long number = payload.arg0(); // 42
}

Changes

  • Append Case to a conflicting record name until it differs from every enclosing Swift type name and the generated Case interface.
  • Use the resulting name consistently for record declarations, payload accessors, and case dispatch.
  • Preserve existing names for cases that do not collide.
  • Add generator regressions for enclosing enum names, outer type names, repeated suffixes, and ordinary names, plus Java runtime tests for renamed records and their associated values.

Validation

  • Confirmed the collision regression fails against the unmodified generator.
  • swift test --disable-experimental-prebuilts --disable-sandbox --filter JNIEnumTests: 11 tests passed.
  • ./gradlew :Samples:SwiftJavaExtractJNISampleApp:test --no-daemon: all 287 Java tests passed with no failures or skips, including the new payload round trips.
  • 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-jni-enum-case-name-collisions branch from 0989f3a to 1e8ce49 Compare October 23, 2026 07:58
@teamhimeh
teamhimeh merged commit 88de54e into qoncept-fork Oct 23, 2026
33 of 42 checks passed
@sidepelican sidepelican added needs-upstream upstreamed swiftlang/swift-java本家でも修正がマージされた and removed needs-upstream labels Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

upstreamed swiftlang/swift-java本家でも修正がマージされた

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants