Table of Contents

5.4.2.18 Exit Function Statement

Note

This section describes the implementation of MS-VBAL §5.4.2.18 Exit Function Statement.

Syntax

AST node Instruction kind Notes
KeywordStatementNode (Token: "Exit Function") ExitProcedure No resolved target.

Exit Function lowers to the same InstructionKind as Exit Sub and Exit Property: ExitProcedure (RD-VBAL §3.5.2 Instruction).

Static Semantics

An Exit Function must be inside the body of a function; in a Sub, or in a Property Let or a Property Set, it is VBC09314 (ExitFunctionNotAllowedInSubOrProperty).

Note

MS-VBAL §5.4.2.18 says the statement must be in a function, and the platform also accepts it in a Property Get, as MS-VBA does. The rule is ExitStatementStaticSemantics's. It is applied when the kind of the procedure is known: StatementStaticSemanticsEvaluator and instruction-list lowering are each told it, and check nothing of the kind without it.

Runtime Semantics

The executor dispatches the ExitProcedure instruction, as for Exit Sub (RD-VBAL §5.4.2.17 Exit Sub Statement).

The function result variable is read back however ExitProcedure was reached: an explicit Exit Function, or reaching the end of the body. The value read back is the call's result (RD-VBAL §5.3.1.11 Procedure Invocation Argument Processing).

Implementation

  • RDCore.Runtime.Execution.ProcedureExecutor dispatches ExitProcedure instructions.
  • RDCore.Runtime.Execution.RuntimeProcedureInvoker reads the function result variable back from ICallStackFrame.ReturnValue.

⏮️ RD-VBAL §5.4.2.17 Exit Sub Statement | ⏭️ RD-VBAL §5.4.2.19 Exit Property Statement