Class ConstructorThisEscapeOrError
java.lang.Object
org.ek9lang.compiler.common.RuleSupport
org.ek9lang.compiler.common.TypedSymbolAccess
org.ek9lang.compiler.phase3.ConstructorThisEscapeOrError
- All Implemented Interfaces:
BiConsumer<EK9Parser.ParamExpressionContext, ISymbol>
final class ConstructorThisEscapeOrError
extends TypedSymbolAccess
implements BiConsumer<EK9Parser.ParamExpressionContext, ISymbol>
Inside a constructor body, 'this' must not be passed as an argument to any NON-PURE call.
Eliminates publication-during-construction races: if 'this' escapes to a thread-spawning receiver (or any receiver that retains the reference) before the constructor has finished initialising fields, another thread can observe partially-initialised state.
Passing 'this' to a PURE receiver is permitted — pure functions have no observable side
effects (no global writes, no thread spawning, no retained references), so they cannot
leak the reference. This allows the Consumer-based delegated-initialisation pattern
(e.g., a pure constructor accepting a Consumer of T as pure and calling
initializer(this)).
Part of EK9's compile-time data-race detection (slice 1, model rule §3.5). Error E08250 THIS_ESCAPES_CONSTRUCTOR.
-
Field Summary
Fields inherited from class RuleSupport
errorListener, symbolsAndScopes -
Constructor Summary
ConstructorsConstructorDescriptionConstructorThisEscapeOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(EK9Parser.ParamExpressionContext paramExpression, ISymbol resolvedTarget) Methods inherited from class TypedSymbolAccess
getRecordedAndTypedSymbol, isProcessingScopePure, recordATypedSymbolMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BiConsumer
andThen
-
Constructor Details
-
ConstructorThisEscapeOrError
ConstructorThisEscapeOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener)
-
-
Method Details
-
accept
- Specified by:
acceptin interfaceBiConsumer<EK9Parser.ParamExpressionContext, ISymbol>
-