ek9_convert_constructor
Replaces the no-arg constructor with its other spelling - 'default Name()' ↔ an explicit 'this.field :=? Type()' default-setter body - purity and visibility preserved; answers status, edits[] and summary.
When to use it
'Expand Person's default constructor so I can customise it' (or collapse it back) is one call with symbol:'Person' - mode is inferred from the constructor.
When not to use it
- The constructor doesn't exist yet - use
ek9_add_constructorto create one. - You want to round-trip an OPERATOR (==, <=>, $, …), not a constructor - use
ek9_expand_default_operator/ek9_collapse_to_default_operator. - The constructor takes parameters and its signature is wrong - use
ek9_change_signature(this is a no-arg form swap, not a structural change). - The constructor should be removed entirely - use
ek9_safe_delete.
Details
Class/record only; the no-arg constructor is found by name (parser-authoritative) and mode is inferred from its form - a 'default' constructor expands, an explicit one collapses; an explicit mode that contradicts the form is status:error. expand emits the guarded ':=?' default-setter, skipping injected ('name as Type!') fields and any field whose declaration already supplies a value (its ':=?' would be dead code, E08095), and errors when no field is left to set (keep 'default'). collapse returns would-fail when losing the explicit body would break the compile - e.g. uninitialised 'as Type?' fields with no co-initialising value ctor (E08070/E07175).
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 constructor declaration. Omit it - the no-arg constructor is found by symbol; needed only when two exist. | |
mode | string: expand | collapse | Optional - inferred from the constructor found: a 'default' constructor expands (→ explicit 'this.field :=? Type()' body), an explicit no-arg one collapses (→ 'default'). | |
symbol | string | yes | The class or record owning the no-arg constructor - a bare name ('Person') finds its file workspace-wide; 'mod::Person' when the name is declared in two modules. |
It also takes the arguments every tool takes.
Recorded calls
Real calls, recorded against small projects and checked on every build - a changed answer fails it.
By name before compile
Request
{
"dryRun" : true,
"symbol" : "Account"
}
Response
{
"conflicts" : [ ],
"edits" : [ ],
"error" : {
"kind" : "not-compiled",
"message" : "symbol:'Account' is found in the compiled workspace, and nothing has been compiled yet - run ek9_compile, then resend this call unchanged (or pass file:'<path>' with the symbol)."
},
"meta" : {
"serverMs" : "<timing>"
},
"nextStep" : "ek9_compile",
"status" : "error",
"summary" : "symbol:'Account' is found in the compiled workspace, and nothing has been compiled yet - run ek9_compile, then resend this call unchanged (or pass file:'<path>' with the symbol).",
"wouldBeDiagnostics" : [ ],
"written" : false
}
See also
- Show me in the IDE: Convert Constructor