extractTypeParameterBounds static method

Map<String, RuntimeType?> extractTypeParameterBounds(
  1. STypeParameterList? typeParameters,
  2. Environment? resolveEnvironment, {
  3. bool lenient = false,
})

SCE130: lenient records an unresolvable bound as null rather than rethrowing. Pass 1 passes it, and resolveDeferredTypeParameterBounds repairs the miss in pass 2 once imports and type aliases exist.

Implementation

static Map<String, RuntimeType?> extractTypeParameterBounds(
  STypeParameterList? typeParameters,
  Environment? resolveEnvironment, {
  bool lenient = false,
}) {
  final bounds = <String, RuntimeType?>{};
  if (typeParameters == null) return bounds;

  for (final typeParam in typeParameters.typeParameters) {
    final paramName = typeParam.name?.name ?? '';
    RuntimeType? bound;

    if (typeParam.bound != null && resolveEnvironment != null) {
      try {
        Logger.debug(
          "[InterpretedClass._extractTypeParameterBounds] Resolving bound for type parameter '$paramName'",
        );

        bound = resolveTypeAnnotationDynamic(
          typeParam.bound!,
          resolveEnvironment,
        );

        Logger.debug(
          "[InterpretedClass._extractTypeParameterBounds] Successfully resolved bound for '$paramName' to: ${bound.name}",
        );
      } catch (e) {
        Logger.debug(
          "[InterpretedClass._extractTypeParameterBounds] Failed to resolve bound for '$paramName': $e",
        );
        // SCE130: see the doc above — pass 1 defers, pass 2 repairs.
        if (!lenient) rethrow;
        bound = null;
      }
    }

    bounds[paramName] = bound;
  }

  return bounds;
}