visitInvocationExpression method

  1. @override
Future<Element>? visitInvocationExpression(
  1. InvocationExpression node
)
override

Implementation

@override
Future<Element>? visitInvocationExpression(InvocationExpression node) async {
  final identifier = await node.identifierExpression.accept(this) as IdentifierElement;
  final argument = await node.argument.accept(this) as ExpressionElement;

  final invocationElement = InvocationElement(
    identifier: identifier,
    argument: argument,
    // TODO(mateusfccp): It will be potentially constant when we have macros
    constant: false,
  );

  identifier.enclosingElement = invocationElement;
  argument.enclosingElement = invocationElement;

  if (identifier.type case final FunctionType functionType) {
    invocationElement.type = functionType.returnType;

    // Check if the argument type matches the parameter type
    return invocationElement;
  } else {
    throw NotAFunctionError(
      syntacticEntity: node.identifierExpression,
      calledType: identifier.type!,
    );
  }
}