5.4.2.1 Call Statement

A <call-statement> invokes a subroutine or function, discarding any return value.

 call-statement = "Call" (simple-name-expression / member-access-expression / index-expression / with-expression)  
 call-statement =/ (simple-name-expression / member-access-expression / with-expression) argument-list 

Static semantics.

  • If the Call keyword is omitted, the first positional argument, if any, can only represent a <with-expression> if it is directly preceded by whitespace.

  • The specified argument list is determined as follows:

    • If the Call keyword is specified:

      • If a <call-statement> element’s referenced expression is an <index-expression>, the specified argument list is this expression’s argument list.

      • Otherwise, the specified argument list is an empty argument list.

    • Otherwise, if the Call keyword is omitted, the specified argument list is <argument-list>.

  • A <call-statement> is invalid if any of the following is true:

    • The referenced expression is not classified as a variable, function, subroutine or unbound member.

    • The referenced expression is classified as a variable and one of the following is true:

      • The declared type of the referenced expression is a type other than a specific class or Object.

      • The declared type of the referenced expression is a specific class without a default function or subroutine.

      • The declared type of the referenced expression is a specific class with a default function or subroutine whose parameter list is incompatible with the specified argument list.

  • The referenced expression is classified as a function or subroutine and its referenced procedure’s parameter list is incompatible with the specified argument list.

    Runtime semantics.

    At runtime, the procedure referenced by the expression is invoked, as follows:

  • If the expression is classified as an unbound member, the member is resolved as a variable, property, function or subroutine, and evaluation continues as if the expression had statically been resolved as a variable expression, property expression, function expression or subroutine expression, respectively.

  • If the expression is classified as a function or subroutine, the expression’s referenced procedure is invoked with the specified argument list. Any return value resulting from the invocation is discarded.

  • If the expression is classified as a variable:

    • If the expression’s data value is an object with a public default function or subroutine, this default procedure is invoked with the specified argument list.

    • If the expression’s data value is an object with a public default property, runtime error 450 (Wrong number of arguments or invalid property assignment) is raised.

    • Otherwise, runtime error 438 (Object doesn’t support this property or method) is raised.

  • If the expression is classified as a property, runtime error 450 (Wrong number of arguments or invalid property assignment) is raised.