feat(enum): implement a trait without passing its companion - #46
Merged
Merged
Conversation
- share val.ts's `Takes`, `Complete`, `Passes` and `Alone`; drop enum.ts's thinner copies - with them, four gates the enum lacked: the mis-call message, a name another trait answers to, a name a variant's field holds, a companion that skipped a Final - `PayloadKeys` distributes, so an enum answers for every variant rather than the shared fields alone - declarations 58.81 to 58.67 kB
- api: the type-argument form was missing from both tables - api: `.impl` and `.implTrait` read as taking a required argument; the enum's `.impl(fns?)` was the only row that said otherwise - notes: §15.2 had no record of the asymmetry; it was never a rejected option, just unwritten - notes: sharing val.ts's gates shrank the declarations, against §15.1's +2.1 kB for the same overloads on a Val
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.
Why
Valaccepts a trait as a type argument when the trait implements nothing of its own:An enum could not. The call failed with
TS2558: Expected 2 type arguments, but got 1, and thesecond argument lost its contextual type along with it. Nothing records the omission as a decision:
notes/design.md§15.2 documents only the companion form, and §9 has no entry.src/enum.tsalso carried its own thinnerTakesandPasses, so five gatesValapplies neverreached an enum: the mis-call message, a member name another trait answers to, a member name a
variant's field holds,
Complete, andAlone.What changed
Val'sTakes,Complete,PassesandAloneare shared instead of copied.enum.tsdropsits own, and both entry points publish the same two overloads
Valdoes.PayloadKeysdistributes.keyofover the union of an enum's payloads keeps the shared fieldsalone, so a member shadowing one variant's field passed the gate.
trait.__valof_shared ?? trait, onetoken, matching
val.ts.api.mdlists the type-argument form, and marks the arguments that were already optional.Cost
The declarations shrink: the two duplicated aliases outweigh the overloads doubling across the two
entry points. §15.1 paid +2.1 kB for the same overloads on a
Val.index.d.mtsenuminstantiationscoreinstantiationsEnumTests
Each gate was removed from the source to confirm a test goes red, on both entry points: the sealer's
and the companion's.
EnumBuilderhad no coverage at first, and losing every gate left the suitegreen.
One behaviour to note
Two gates now reject code that compiled before: a trait member shadowing one variant's field, and
two traits answering to the same member name. Both were holes rather than allowances, and
Enumships from
valof/experimental, so this is labelled as a fix rather thanbreaking. Say if itbelongs in the release notes as one.