Skip to content

wrap-java: handle sealed/permits in interfaces and classes#843

Open
ktoso wants to merge 2 commits into
swiftlang:mainfrom
ktoso:wip-sealed-permits-args
Open

wrap-java: handle sealed/permits in interfaces and classes#843
ktoso wants to merge 2 commits into
swiftlang:mainfrom
ktoso:wip-sealed-permits-args

Conversation

@ktoso

@ktoso ktoso commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

This updates the JavaClass and interface macros with additional permits which handle Java's sealed.

@JavaClass(.sealed, "com.example.Shape", permits: Circle.self, Square.self)
@JavaClass(.final,  "com.example.Leaf")

I decided to not change codegen so far, since we have a good enough func as(T) -> T? already; so this is mostly docs; but we could generate way more now, including switching over the "case" of it using Swift enums.

@ktoso ktoso force-pushed the wip-sealed-permits-args branch from 1dd36d2 to e0fac04 Compare July 13, 2026 06:54
When we know the exact set of permitted subclasses we should include
them in the generated macro such that we can then from the macro
generate safe `as...()` methods.

These are useful since it is common to use subclassing with sealed
hierarchies like that. The normal `as` still exists.
@ktoso ktoso force-pushed the wip-sealed-permits-args branch from e0fac04 to c0e43e7 Compare July 13, 2026 07:22
@ktoso ktoso force-pushed the wip-sealed-permits-args branch from c0e43e7 to d13e42d Compare July 14, 2026 07:00
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