ek9_collapse_to_default_operator
Replaces the operator's declaration and body with the one-line 'default operator <sym>' form (the inverse of ek9_expand_default_operator); answers status, edits[] and summary.
When to use it
'Collapse Order's hand-written == back to default operator ==' is one call with symbol:'Order' and operator:'==' - the body must be default-equivalent.
When not to use it
- You want the OPPOSITE - turn 'default operator <sym>' into an explicit body so you can customise it - use
ek9_expand_default_operator. - The operator should be REMOVED entirely, not collapsed - use
ek9_safe_delete. - The operator's signature/purity is wrong and needs structural change - use
ek9_change_signature. - The body is genuinely customised - the tool does NOT diff it against the synthesis and will silently discard the custom behaviour; review with
ek9_read_constructfirst.
Details
Class/record/component only; the defaultable set is <=> == ? $ $$ #? :=: - <> < <= > >= are generated from the sameness and never written or requested (E07181; E07180 where the type has no <=> to generate them from), and any other operator errors ('cannot be defaulted'). The operator's declaration is found by name; two explicit declarations of the same symbol (overloads) are a conflict listing their lines - pass line to pick one. The whole declaration + body is replaced without being diffed against the compiler's synthesis, so a customised body is silently lost. The verify compile only catches breakage the collapse itself introduces (e.g. E07030 default-on-trait, E07190 super missing '<=>', a field type lacking the operator).
Arguments
| Argument | Type | Required | What it is |
|---|---|---|---|
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 | IDE refinement: the 1-based line of the operator declaration. Omit it - the declaration is found by symbol + operator; needed only when two overloads declare the same operator. | |
operator | string | yes | The operator to collapse, in EK9 source form ('==', '<=>', '$'); must be in the defaultable set. |
symbol | string | yes | The class, record or component holding the operator - a bare name ('Order') finds its file workspace-wide; 'mod::Order' when the name is declared in two modules. |
It also takes the arguments every tool takes.
See also
- Show me in the IDE: Expand Default Operator