Class NestedCallInThrowOrError

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

final class NestedCallInThrowOrError extends Object implements Consumer<EK9Parser.ThrowStatementContext>
Detects `throw` statements whose expression is a nested call (E11070).

EK9 allows two forms of throw:

  • throw Exception("reason") — direct constructor call
  • throw existingVariable — previously-declared variable

It does NOT allow a nested call in throw position:

  throw getFactory("std")("oops")   //Rejected — extract a variable

The fix is always the same — extract an intermediate variable so the exception construction is visible at the throw site:

  factory <- getFactory("std")
  ex      <- factory("oops")
  throw ex

Detection uses pure grammar structure: a throw call is a nested call when the throw's call context has its own inner call child (i.e. it is a Alt6 call paramExpression construction).