Class GuardedAssignmentPromotion
#^ promotion of a guarded assignment's right-hand side - use this, do not re-derive it.
Phase 3 deliberately permits coercion in a guard: ?= is a member of
OperationIsAssignment, so TypesCompatibleOrError accepts any
getCostOfMatch >= 0. Character -> String is coercible, so
t ?= charSource() with t as String is a clean compile BY DESIGN. Phase 3 resolves
the coercion; phase 7 must insert the _promote() call.
Where it is skipped, the RHS's declared type is stored into a slot typed by the target's declared type and the class fails JVM verification at load: "Type 'org/ek9/lang/Character' is not assignable to 'org/ek9/lang/String'". That is a clean compile followed by a hard failure, for a construct that is the language's designated replacement for early return.
Three copies of the guard lowering existed and only the if one promoted, so a guard under
while, try, for and switch miscompiled while the identical guard
under if ran correctly. This is the single place that decision is now made.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
GuardedAssignmentPromotion
-
-
Method Details
-
promoteIfRequired
public String promoteIfRequired(List<IRInstr> target, ISymbol rhsSymbol, ISymbol targetSymbol, String rhsVariable, DebugInfo debugInfo) Promote the guarded RHS to the target's declared type when the two differ but are coercible.- Parameters:
target- instruction list receiving any promotion callrhsSymbol- the resolved symbol of the guard expression's right-hand sidetargetSymbol- the resolved symbol of the guard's target identifierrhsVariable- the IR variable currently holding the RHS valuedebugInfo- debug info for any emitted promotion- Returns:
- the variable to store - the promoted one where promotion applied, else the original
-