callableRuntimeType property

RuntimeType get callableRuntimeType

DFUB5: the structural function type of this callable, used by is/as and return-type checks against T Function(...) annotations.

Implementation

RuntimeType get callableRuntimeType {
  final cached = _cachedCallableRuntimeType;
  if (cached != null) return cached;
  final returnType = declaredReturnType ?? const NamedRuntimeType('dynamic');
  final positional = <RuntimeType>[];
  final optionalPositional = <RuntimeType>[];
  final named = <String, RuntimeType>{};
  final params = _parameters?.parameters;
  if (params != null) {
    for (final param in params) {
      final paramType = _paramRuntimeType(param, _closure);
      if (param.isNamed) {
        named[_paramName(param) ?? ''] = paramType;
      } else if (param.isOptional) {
        optionalPositional.add(paramType);
      } else {
        positional.add(paramType);
      }
    }
  }
  return _cachedCallableRuntimeType = FunctionRuntimeType(
    returnType: returnType,
    positionalParameterTypes: positional,
    optionalPositionalParameterTypes: optionalPositional,
    namedParameterTypes: named,
  );
}