Skip to content

jextract/jni: Support enums that have no cases#577

Closed
sidepelican wants to merge 1 commit intoswiftlang:mainfrom
sidepelican:no_case_enum2
Closed

jextract/jni: Support enums that have no cases#577
sidepelican wants to merge 1 commit intoswiftlang:mainfrom
sidepelican:no_case_enum2

Conversation

@sidepelican
Copy link
Contributor

Currently, when the Swift enum has no cases, the generated Java code results in a compilation error.

error: sealed class must have subclasses
  public sealed interface Case {}
                ^

In Swift, it is a common idiom to use enums with no cases as namespaces.
In cases where no enum cases exist, I will remove sealed to ensure that no compilation errors occur.

@ktoso
Copy link
Collaborator

ktoso commented Feb 27, 2026

Thanks!

let selfPointer = self.printSelfJLongToUnsafeMutablePointer(
&printer,
swiftParentName: type.swiftNominal.name,
swiftParentName: type.swiftNominal.qualifiedName,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have found another problem again

error: cannot find type 'Nested' in scope
544 |   assert(selfPointer != 0, "selfPointer memory address was null")
545 |   let selfBits$ = Int(Int64(fromJNI: selfPointer, in: env$))
546 |   guard let self$ = UnsafeMutablePointer<Nested>(bitPattern: selfBits$) else {
    |                                          `- error: cannot find type 'Nested' in scope
547 |     fatalError("self memory address was null in call to \(#function)!")
548 |   }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah ouch

@ktoso
Copy link
Collaborator

ktoso commented Feb 27, 2026

You know what, let's accept your other PR, it's simple enough. I don't think we need to over think this that much, not emitting the sealed interface will be fine

@ktoso ktoso closed this Feb 27, 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.

2 participants