A3: at most one constructed superclass - #9
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Kotlin declaration model to make “at most one constructed superclass” structurally enforceable, matching Kotlin’s constraint that only one superclass may be constructed while any number of interfaces may be implemented.
Changes:
- Replaces the single
supertypes: Vec<(KtType, Option<KtCode>)>list withKtSupertypes { superclass, interfaces }plus aKtSuperclasspayload. - Splits the builder API from
.supertype(ty, args)into.extends(ty, args)and.implements(ty), and makes rendering order structural (superclass first). - Updates rendering/import collection and adds tests for ordering, bare superclass rendering, and double-
extendspanic behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/model.rs | Introduces KtSuperclass/KtSupertypes and updates class/companion supertype modeling and builder APIs. |
| src/render.rs | Switches supertypes rendering/import collection to the new KtSupertypes iterator and enforces superclass-first render ordering. |
| src/tests.rs | Migrates tests to new API and adds coverage for ordering, bare superclass, and double-extends panic. |
| src/lib.rs | Exports the new KtSuperclass and KtSupertypes types as part of the public API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+448
to
452
| /// Implement an interface. | ||
| pub fn implements(mut self, ty: KtType) -> Self { | ||
| self.supertypes.interfaces.push(ty); | ||
| self | ||
| } |
This was referenced Aug 6, 2026
Supertypes were one undifferentiated `Vec<(KtType, Option<KtCode>)>`
where any number of entries could carry constructor arguments, so
`class A : B(x), C(y)` — which Kotlin rejects, a class may construct at
most one superclass — rendered happily.
Split the list by role:
pub struct KtSupertypes {
superclass: Option<KtSuperclass>, // at most one, may be constructed
interfaces: Vec<KtType>, // any number, never constructed
}
`.supertype(ty, args)` is replaced by `.extends(ty, args)` and
`.implements(ty)`, which forces the caller to say which role a supertype
plays instead of leaving it implied by whether arguments were passed. A
second `.extends` panics rather than silently dropping the first.
Render order becomes structural: the superclass always leads, whatever
order the builder calls came in.
All 43 pre-existing tests pass untouched; three added.
milyin
force-pushed
the
step/a3-supertype-split
branch
from
August 6, 2026 11:40
42802fc to
808547c
Compare
milyin
force-pushed
the
step/a2-companion-type
branch
from
August 6, 2026 11:40
191a2c1 to
2aee77c
Compare
milyin
changed the base branch from
step/a2-companion-type
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.
Third step of #6. Stacked on #8.
Supertypes were one undifferentiated list where any number of entries could
carry constructor arguments:
so
class A : B(x), C(y)rendered happily. Kotlin rejects it — a class mayconstruct at most one superclass.
API change
.supertype(ty, args)splits into.extends(ty, args)and.implements(ty).The old single method left the role of a supertype implied by whether the
caller happened to pass arguments — an interface and an argument-less
superclass were indistinguishable. Now the caller says which it is.
A second
.extendspanics rather than silently dropping the first, which iswhat a plain overwrite would have done.
Render order is now structural
The superclass always leads, whatever order the builder calls came in — Kotlin
wants it first, and that is no longer the caller's job to remember:
Verification
All 43 pre-existing tests pass untouched. Three added: ordering, an
argument-less superclass (
: Base, for a subclass with no primary constructorthat delegates from secondary ones), and the double-
extendspanic.cargo clippy --all-targetsclean.