A4: a fun interface method has no body - #10
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Ready to approve
The changes consistently enforce Kotlin SAM constraints, update rendering/import collection paths accordingly, and add targeted tests for the new behavior.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
This PR strengthens the Kotlin declaration model by making fun interface (SAM) methods structurally unbuildable with bodies, introducing KtFunSig as a bodyless/modifierless function signature and reusing it for abstract-member rendering and import collection.
Changes:
- Introduces
KtFunSigand switchesKtFunInterface::methodfromKtFuntoKtFunSigto prevent bodied SAM methods. - Refactors rendering to share a single signature-layout implementation between
KtFunandKtFunSigviaSigView, and updates raw-import collection accordingly. - Adds tests covering
fun interfacerendering, usingKtFunSigas an interface member, andKtFun::signature()round-tripping.
File summaries
| File | Description |
|---|---|
| src/model.rs | Adds KtFunSig, updates KtFunInterface to store a signature, and adds KtFun::signature() conversion. |
| src/render.rs | Adds shared signature rendering (SigView), adds render_fun_sig, and updates import collection for signature-only functions. |
| src/tests.rs | Updates raw-import collection test for SAM signatures and adds 3 new tests for the new API/behavior. |
| src/lib.rs | Re-exports KtFunSig as part of the public API surface. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
15 tasks
`KtFunInterface::method` was a full `KtFun`, which can carry a body, and `render_fun_interface` rendered the method verbatim — body included. A `fun interface` must have exactly one *abstract* method, so that output had none at all and did not compile. Introduce `KtFunSig`: everything a `KtFun` has except a body and modifiers. `KtFunInterface::method` holds one, so a bodied SAM method is unrepresentable. The type earns its keep beyond that: an abstract member *is* a signature. `KtFunSig` converts into `KtFun` (body `None`) and into `KtDecl`, so an interface can declare `.member(KtFunSig::new(...))` instead of reaching for a body-less `KtFun`; `KtFun::signature()` goes the other way, replacing the strip-body-and-modifiers helper a consumer would otherwise hand-write. `KtFun` and `KtFunSig` share one layout implementation through an internal `SigView`, so the width-driven parameter breaking is not duplicated. All 46 pre-existing tests pass untouched.
milyin
force-pushed
the
step/a4-fun-signature
branch
from
August 6, 2026 11:40
b3c8bd1 to
ce48226
Compare
milyin
force-pushed
the
step/a3-supertype-split
branch
from
August 6, 2026 11:40
42802fc to
808547c
Compare
milyin
changed the base branch from
step/a3-supertype-split
to
docs/validation-umbrella
August 6, 2026 11:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fourth step of #6. Stacked on #9.
KtFunInterface::methodwas a fullKtFun, which can carry a body, andrender_fun_interfacerendered it verbatim — body included. Afun interfacemust have exactly one abstract method, so that output had none at all:
KtFunSigis everything aKtFunhas except a body and modifiers.KtFunInterface::methodholds one, so the shape is now unbuildable.The type earns its keep twice
An abstract member is a signature, so
KtFunSigis the natural way todeclare one:
KtFunSigconverts intoKtFun(bodyNone) and intoKtDecl;KtFun::signature()goes the other way. That last one replaces thestrip-the-body-and-modifiers helper a consumer would otherwise hand-write —
prebindgen-jnihas exactly such a function today.Rendering
KtFunandKtFunSigshare one layout implementation through an internalSigView, so the width-driven parameter breaking is factored out rather thanduplicated. Import collection splits too: a signature has no body, so only
parameter defaults can carry imports.
Verification
All 46 pre-existing tests pass untouched. Three added: the rendered
fun interface, a signature used as an interface member, and theKtFun::signature()round trip.cargo clippy --all-targetsclean.