3393befc99
In this CL methods StructuralParameterType.forAlphaRenaming, StructuralParameterType.forAlphaRenamingFromTypeParameter, TypeParameterType.forAlphaRenaming, and TypeParameterType.forAlphaRenamingFromStructuralParameter are removed, and their call sites are replaced with invocations of other constructors of StructuralParameterType and TypeParameterType. The reason for this change is call sites having more information for correct computing of type nullabilities. In addition to the primary update, the following related changes are made in this CL. * Method StructuralParameterType.computeDefaultNullabilityForLibrary is renamed into StructuralParameterType.computeDefaultNullability, and TypeParameterType.computeDefaultNullabilityForLibrary is renamed into TypeParameterType.computeDefaultNullability. The parameter `library` is removed from both methods, since it's no longer needed. * The static methods named `computeNullabilityFromBound` are removed from `StructuralParameterType` and `TypeParameterType` and re-introduced as instance members in classes `StructuralParameter` and `TestParameter` respectively TEST=existing Change-Id: I26cccf17ccc9bda1e8b750196f427325b544a7ac Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402820 Reviewed-by: Johnni Winther <johnniwinther@google.com> Reviewed-by: Mayank Patke <fishythefish@google.com> Reviewed-by: Alexander Markov <alexmarkov@google.com>
70 lines
2.6 KiB
Dart
70 lines
2.6 KiB
Dart
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'package:kernel/ast.dart';
|
|
|
|
/// Returns a [Component] object containing empty definitions of core SDK
|
|
/// classes.
|
|
Component createMockSdkComponent() {
|
|
Library coreLib = new Library(Uri.parse('dart:core'),
|
|
name: 'dart.core', fileUri: Uri.parse('dart:core'));
|
|
Library asyncLib = new Library(Uri.parse('dart:async'),
|
|
name: 'dart.async', fileUri: Uri.parse('dart:async'));
|
|
Library internalLib = new Library(Uri.parse('dart:_internal'),
|
|
name: 'dart._internal', fileUri: Uri.parse('dart:_internal'));
|
|
|
|
Class objectClass = new Class(name: 'Object', fileUri: coreLib.fileUri);
|
|
coreLib.addClass(objectClass);
|
|
|
|
Class addClass(Library lib, String name,
|
|
{Supertype? supertype,
|
|
List<TypeParameter>? typeParameters,
|
|
List<Supertype>? implementedTypes}) {
|
|
Class c = new Class(
|
|
name: name,
|
|
supertype: supertype ?? objectClass.asThisSupertype,
|
|
typeParameters: typeParameters,
|
|
implementedTypes: implementedTypes,
|
|
fileUri: lib.fileUri);
|
|
lib.addClass(c);
|
|
return c;
|
|
}
|
|
|
|
InterfaceType objectType =
|
|
new InterfaceType(objectClass, coreLib.nonNullable);
|
|
|
|
TypeParameter typeParam(String name, [DartType? bound]) {
|
|
return new TypeParameter(name, bound ?? objectType);
|
|
}
|
|
|
|
addClass(coreLib, 'Null');
|
|
addClass(coreLib, 'bool');
|
|
Class num = addClass(coreLib, 'num');
|
|
addClass(coreLib, 'String');
|
|
Class iterable =
|
|
addClass(coreLib, 'Iterable', typeParameters: [typeParam('T')]);
|
|
{
|
|
TypeParameter T = typeParam('T');
|
|
addClass(coreLib, 'List', typeParameters: [
|
|
T
|
|
], implementedTypes: [
|
|
new Supertype(iterable, [new TypeParameterType.withDefaultNullability(T)])
|
|
]);
|
|
}
|
|
addClass(coreLib, 'Map', typeParameters: [typeParam('K'), typeParam('V')]);
|
|
addClass(coreLib, 'int', supertype: num.asThisSupertype);
|
|
addClass(coreLib, 'double', supertype: num.asThisSupertype);
|
|
addClass(coreLib, 'Iterator', typeParameters: [typeParam('T')]);
|
|
addClass(coreLib, 'Symbol');
|
|
addClass(coreLib, 'Type');
|
|
addClass(coreLib, 'Function');
|
|
addClass(coreLib, 'Invocation');
|
|
addClass(coreLib, 'Future', typeParameters: [typeParam('T')]);
|
|
addClass(asyncLib, 'FutureOr', typeParameters: [typeParam('T')]);
|
|
addClass(asyncLib, 'Stream', typeParameters: [typeParam('T')]);
|
|
addClass(internalLib, 'Symbol');
|
|
|
|
return new Component(libraries: [coreLib, asyncLib, internalLib]);
|
|
}
|