Class ConstructionRecursionOrError
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 Summary
ConstructorsConstructorDescriptionConstructionRecursionOrError(ConstructionEdges constructionEdges, Parameterisations parameterisations, Function<IToken, ErrorListener> errorListenerForToken) Create the check over the always-run calls collected in this compile. -
Method Summary
Modifier and TypeMethodDescriptionvoidcheck()Find every construction cycle and report each one once, in source order.
-
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 walkparameterisations- every concrete parameterisation in the programerrorListenerForToken- 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.
-