A5: external is a body kind, not a modifier - #11
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Moves Kotlin external from a free-form function modifier string into the typed function body representation (KtBody::External) so external fun … { … } becomes unrepresentable in the model, while keeping rendering order consistent and adding regression tests.
Changes:
- Add
KtBody::Externaland a dedicatedKtFun::external()builder; reject"external"passed viaKtFun::modifier(...). - Update rendering/import-collection logic to treat
Externallike a bodiless function while still rendering theexternalkeyword ahead of other modifiers. - Update and add tests covering rendering, mutual exclusion of
externalvs body, and the modifier-string panic.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/model.rs | Introduces KtBody::External, adds KtFun::external(), and guards against "external" being added via modifier(). |
| src/render.rs | Renders external from the body-kind and treats External like None for body output and body-import collection. |
| src/tests.rs | Migrates existing tests to .external() and adds new tests for rendering, exclusivity, and the panic guard. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+784
to
+790
| let m = m.into(); | ||
| assert!( | ||
| m != "external", | ||
| "`external` is not a modifier here — use `KtFun::external()`, which \ | ||
| also rules out giving the function a body" | ||
| ); | ||
| self.modifiers.push(m); |
This was referenced Aug 6, 2026
`external` was a free-form string in `KtFun::modifiers` while the body
lived in a separate field, so `external fun f(): Int { … }` — a function
that is both natively implemented and has a body — was representable and
rendered.
Make it a `KtBody` variant. Both live in the one `body` field now, so
setting either clears the other and the combination has nowhere to
exist. `KtFun::external()` replaces `.modifier("external")`, and passing
the string panics with a message pointing at it, so the old spelling
cannot quietly reintroduce the hole.
`KtBody::None` stays: whether a bodiless function is legal depends on
where it sits — an interface member needs no keyword — and position is
not something a type can capture here. That one remains for the
validator.
All 49 pre-existing tests pass; `external` renders in the same place as
before. Three added.
milyin
force-pushed
the
step/a4-fun-signature
branch
from
August 6, 2026 11:40
b3c8bd1 to
ce48226
Compare
milyin
force-pushed
the
step/a5-external-body
branch
from
August 6, 2026 11:40
75908e0 to
d1c977f
Compare
milyin
changed the base branch from
step/a4-fun-signature
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.
Fifth and last structural step of #6. Stacked on #10.
externalwas a free-form string inKtFun::modifierswhile the body lived ina separate field, so this was representable and rendered:
Making it a
KtBodyvariant puts both in the same field, so setting eitherclears the other and the combination has nowhere to exist:
KtFun::external()replaces.modifier("external"), and passing the stringpanics with a message pointing at it — otherwise the old spelling would quietly
reintroduce the hole this PR closes.
What stays for the validator
KtBody::Noneremains. Whether a bodiless function is legal is positional —an
interfacemember needs no keyword, an abstract class member does — andposition is not something a type can capture here. It is listed as B3 in the
umbrella.
Verification
All 49 pre-existing tests pass;
externalrenders in exactly the same positionas before, so no golden string moved. Three added: rendering, the
mutual-exclusion property, and the modifier-string panic.
cargo clippy --all-targetsclean.Part A is complete with this PR. Five shapes that used to render as
non-compiling Kotlin are now unbuildable: constructor parameters on kinds that
have no constructor, empty
data class, wrong-arityvalue class, top-levelcompanion object, two constructed superclasses, a bodiedfun interfacemethod, and
externalwith a body.