Class CannotAssignFromSanitizedOrError
java.lang.Object
org.ek9lang.compiler.common.RuleSupport
org.ek9lang.compiler.common.TypedSymbolAccess
org.ek9lang.compiler.phase3.CannotAssignFromSanitizedOrError
Blocks direct assignment from sanitized parameters to local variables.
This prevents hiding the copy semantics of sanitized parameters.
someFunction(data as sanitized String) local <- data // ERROR: Creates alias, hides copy semantics local := data // ERROR: Same issue result: data // OK: Returning the value is allowed this.field: data // OK: Storing in field is allowedThe developer should either use the sanitized parameter directly or make an explicit copy: local <- String(data)
Assignment to return variables and fields is allowed because: - Returning a sanitized value doesn't create confusing local aliases - Storing in a field is an intentional action to persist the sanitized value
-
Field Summary
Fields inherited from class RuleSupport
errorListener, symbolsAndScopes -
Constructor Summary
ConstructorsConstructorDescriptionCannotAssignFromSanitizedOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) -
Method Summary
Methods inherited from class TypedSymbolAccess
getRecordedAndTypedSymbol, isProcessingScopePure, recordATypedSymbol
-
Constructor Details
-
CannotAssignFromSanitizedOrError
CannotAssignFromSanitizedOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener)
-
-
Method Details
-
accept
Check if assignment from a sanitized parameter is allowed.- Parameters:
assignmentOp- The token representing the assignment operatorlhsSymbol- The left-hand side symbol being assigned torhsSymbol- The right-hand side symbol (potential sanitized parameter)
-