visitAsExpression method

  1. @override
Object? visitAsExpression(
  1. SAsExpression node
)
override

Visit a SAsExpression.

Implementation

@override
Object? visitAsExpression(SAsExpression node) {
  final value = node.expression!.accept<Object?>(this);
  // ghissues62: an awaited operand suspends; hand the suspension up so
  // the state machine resumes this node instead of using the request
  // as a value.
  if (value is AsyncSuspensionRequest) return value;
  final result = _tryCast(value, node.type);
  if (!identical(result, _castFailed)) return result;
  final typeDesc = _castTypeDescription(node.type);
  // ghissues67: a script collection is described by its written type.
  final valueDesc =
      (WrittenCollectionType.of(value) ?? value?.runtimeType)?.toString() ??
      'Null';
  throw D4rtTypeError(
    "Cast failed with 'as' : value of type $valueDesc cannot be cast to $typeDesc",
  );
}