Home /Modules/compiler/CONSTRUCTOR-SERIES.md

CONSTRUCTOR-SERIES.md

lib/compiler/CONSTRUCTOR-SERIES.md · 35 line(s) · markdown

SLeeLa Constructor Series and Joining Structure

Purpose

Provide one authoritative model for constructor selection, constructor chaining, instance initialization, and allocation. The series joins constructor declarations into a validated initialization plan before IR lowering.

Joining sequence

type lookup -> constructor set -> overload resolution -> access/capability check -> allocation plan -> base/delegating constructor chain -> field initializers -> constructor body -> publish initialized instance

  1. Type lookup: resolve the declared type and its namespace.
  2. Constructor set: collect constructors visible for the selected type and language profile.
  3. Overload resolution: choose one best match using declared parameter types and language conversion rules. Ambiguity is an error.
  4. Validation: check visibility, capabilities, argument compatibility, and inheritance/base initialization rules.
  5. Chain planning: represent this(...) delegation and base-constructor calls as explicit edges.
  6. Cycle detection: reject constructor-delegation cycles.
  7. Initialization order: execute base initialization, instance field initializers, and the selected constructor body in the order defined by the language specification.
  8. Commit object state: publish the instance only after successful initialization; clean up allocation and owned resources on failure.

Invariants

Intermediate representation

Represent the series as a directed graph with a single selected entry constructor. Each edge identifies a delegation or base-construction step. The graph must be acyclic; the lowering stage emits a deterministic initialization sequence from the validated graph.

Diagnostics

Report distinct errors for missing constructors, ambiguous overloads, inaccessible constructors, incompatible arguments, invalid base calls, delegation cycles, capability denial, allocation failure, and initialization failure.