Class PreferStringInterpolationOrError

java.lang.Object
org.ek9lang.compiler.phase5.PreferStringInterpolationOrError
All Implemented Interfaces:
Consumer<EK9Parser.ExpressionContext>

final class PreferStringInterpolationOrError extends Object implements Consumer<EK9Parser.ExpressionContext>
Detects string concatenation chains with 3 or more parts and recommends string interpolation instead (E11068).

EK9 has a bespoke STRING_INTERPOLATION IR instruction that backends optimise to a single allocation. In contrast, each + on strings calls the pure _add operator, creating a new intermediate String object per operation. A chain of a + " " + b + " " + c creates 4 temporaries; the equivalent interpolation `${a} ${b} ${c}` creates 1.

Only flags chains at the root of the left-associative tree to prevent double-reporting. Non-String addition (arithmetic) is ignored via a type check.