Class SlotAssignedOnce

java.lang.Object
org.ek9lang.compiler.phase5.SlotAssignedOnce

final class SlotAssignedOnce extends Object
THE "may this slot already hold a value here?" test for a slot that may be assigned AT MOST ONCE ON ANY PATH: a closeable property in its own constructor, and a closeable returning variable declared unset (D3 extended to every closeable slot, 2026-10-06). Use it for any such slot; do not write another path walk.

It is the MAY half of the existing flow state. The MUST half - "set on every path that reaches here" - is the E08060 path state, read through SymbolsAndScopes, and callers still ask it first (it also sees what a this(...) delegate set). Must-set cannot see a slot set on only SOME paths, which is exactly the leak: set in one arm of an if and set again after it, set in a try body and again in its catch, or set in a loop body that runs twice. This answers, from the parse tree alone, with the slot's earlier assignments recorded in source order (the listener's walk order):

  • an assignment inside a loop body (while, do, for) that lies within the slot's owner can run again, so the slot may already hold the value the previous iteration stored;
  • an earlier assignment to the same slot in the same owner may already have run, unless the two are in DIFFERENT arms of one if/else if/else or one switch (its cases and default) - the only constructs where at most one of two places runs. A try body and its catch are not exclusive: the body may have stored the value before something after it threw.

The OWNER is the nearest enclosing body (function, method, operator, service operation, dynamic function) or the switch/try/while/for whose own returning variable or try resource the slot is - so a loop AROUND a switch expression does not count against the switch's returning variable, which is a new variable each time the switch runs, while a while expression's own body does count against its returning variable.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) boolean
    mayAlreadyHold(ISymbol slot, org.antlr.v4.runtime.tree.ParseTree assignment)
    True when the slot may already hold a value at this assignment, judged from the assignments recorded so far; the assignment is then recorded, so call this once for every assignment to the slot, in source order.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • mayAlreadyHold

      boolean mayAlreadyHold(ISymbol slot, org.antlr.v4.runtime.tree.ParseTree assignment)
      True when the slot may already hold a value at this assignment, judged from the assignments recorded so far; the assignment is then recorded, so call this once for every assignment to the slot, in source order.