ek9_seal_type
Adds 'allow only A, B, C' to a class or trait declaration (plus 'as open' on a class that has no extensibility modifier); answers status, edits[] and conflicts[] naming any entry that does not extend the target or any existing subtype left off the list.
When to use it
'Seal Shape to Circle and Square' is one call with symbol:'Shape', allowOnly:['Circle','Square'] - no file or line needed. Use it to INITIALLY seal a class or trait to a known, fixed subtype list for exhaustive dispatch or API lock-down.
When not to use it
- The type is ALREADY sealed and you just want to add entries - use
ek9_add_to_sealed_allowlist. - You want the OPPOSITE, removing an existing 'allow only' clause — use
ek9_unseal_type. - You want extensibility WITHOUT a fixed subtype list (just 'as open') — use
ek9_make_open. - You want forced subclassing WITHOUT a fixed list — use
ek9_make_abstract.
Details
Class/trait targets only — records/components/functions error. Every allowOnly entry must ALREADY extend/implement the target (conflicts: entry-does-not-extend-target), and the language requires concrete entries — an abstract entry fails the dry-run compile per E05250. Sealed CLASSES need 'as open' or 'as abstract' per E05270 (existing modifier kept, else 'as open' auto-emitted; traits need none); an already-sealed target returns conflicts (target-already-sealed).
Arguments
| Argument | Type | Required | What it is |
|---|---|---|---|
allowOnly | array of string | yes | The 'allow only' list: every concrete class that may extend/implement the target, at any depth. |
file | string | The EK9 source file - OPTIONAL when symbol is a construct name; required to anchor on a member or a use site. | |
line | integer | 1-based line of the declaration or a reference - OMIT it and pass symbol:'<name>' to let the tool find the line (a model counting lines in a file miscounts); if you do count, use ek9_read_file(lineNumbers:true). | |
symbol | string | A construct NAME alone ('Shape', 'sample.deps.core::Validator') - no file needed, the tool finds it workspace-wide; or, with file (+ line), the identifier you mean there. |
It also takes the arguments every tool takes.
See also
- Show me in the IDE: Seal Type