Class ConstructionRecursionOrError

java.lang.Object
org.ek9lang.compiler.phase5.construction.ConstructionRecursionOrError

public final class ConstructionRecursionOrError extends Object
FE77: construction that can never complete (E08263). A type whose construction ALWAYS constructs the same type again - through a property initialiser, a constructor body, a this(...) cycle, a function or a closed method, or a generic's T() - compiles to a guaranteed StackOverflowError, so it is a compile error.

The graph. Nodes are callables - constructors, _i_init, functions, methods - and each edge is a call that ALWAYS runs and is statically dispatched (ConstructionEdges). A cycle in that graph means that once any member runs none can finish. A cycle is reported when it contains a constructor or an _i_init, whether or not anything constructs the type yet: the type can never be built.

🔑 A generic's members are a node PER PARAMETERISATION. A node is the call-graph identity together with the parameterisation it runs as. The call graph deliberately folds every parameterisation onto its template (D15); using that folded key here would merge Base of X with Base of Y and invent cycles. So a template's always-run calls are recorded once and applied to each parameterisation as it is reached: T() becomes a construction of the substituted type, and Inner of T the existing Inner of Leaf.

Sound, and partial on purpose. Calls that only MAY run (any conditional, loop, catch, short-circuit, :=?, stream stage) and calls that dispatch at run time (trait, open-type and abstract methods, dispatchers, function delegates) are not followed, and a substitution FULL_RESOLUTION never made is not invented. Each of those can only hide a cycle, never report one that cannot happen.

  • Constructor Details

    • ConstructionRecursionOrError

      public ConstructionRecursionOrError(ConstructionEdges constructionEdges, Parameterisations parameterisations, Function<IToken, ErrorListener> errorListenerForToken)
      Create the check over the always-run calls collected in this compile.
      Parameters:
      constructionEdges - the always-run calls from the call-graph walk
      parameterisations - every concrete parameterisation in the program
      errorListenerForToken - the error listener of the source a token is in
  • Method Details

    • check

      public void check()
      Find every construction cycle and report each one once, in source order. The search order does not matter: a node belongs to the same cycle whichever root reaches it first, and each error's place is chosen from the cycle itself.