Class ObjectUsedBeforeConstructedOrError
java.lang.Object
org.ek9lang.compiler.common.RuleSupport
org.ek9lang.compiler.common.TypedSymbolAccess
org.ek9lang.compiler.phase5.ObjectUsedBeforeConstructedOrError
An object cannot be used before it is fully constructed (E08061).
Construction runs the super constructor, then this type's property initialisers in declaration order, then the constructor body. Until every property has a value, calling a method on the object - or handing out 'this' - can reach a property that is still unset, and it failed with a NullPointerException at run time (front-end audit FE32). This is the two-phase rule: the object may not be used until it is complete.
- A property initialiser runs before the constructor body, so the object is never complete there: no method call on it (even an inherited one - an inherited method can call back into one this type overrides) and no use of 'this' as a value.
- A constructor may use the object once every property is set on the current path (the flow tracking E08060
already does) - counting what a 'this(...)' call set, which is only what the constructor it delegates to sets
(
DelegatedConstructorInitialisation): a private one may set nothing. Never inside the arguments of 'this(...)' or 'super(...)': nothing has been constructed yet. - In an open or abstract type, a constructor can never call a method a subtype may override, nor hand out 'this': the subtype's own properties are only set after this constructor returns.
Reading and writing a property (this.count) is not a use of the object: E08060 checks each property.
-
Field Summary
Fields inherited from class RuleSupport
errorListener, symbolsAndScopes -
Constructor Summary
ConstructorsConstructorDescriptionObjectUsedBeforeConstructedOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) -
Method Summary
Modifier and TypeMethodDescription(package private) voidA method called with no receiver - on the object itself - such astwice().(package private) voidA use of 'this' or 'super': a call through it, or 'this' as a value.Methods inherited from class TypedSymbolAccess
getRecordedAndTypedSymbol, isProcessingScopePure, recordATypedSymbol
-
Constructor Details
-
ObjectUsedBeforeConstructedOrError
ObjectUsedBeforeConstructedOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener)
-
-
Method Details
-
acceptCall
A method called with no receiver - on the object itself - such astwice(). -
acceptPrimaryReference
A use of 'this' or 'super': a call through it, or 'this' as a value. Reaching a property is not a use.
-