Skip to content

Commit b988928

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Declare type system fields as Dart2TypeSystem where we cast them.
[email protected] Change-Id: I88fea5ee5ba278dbdaf350ff1db7407d2d8625d0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117821 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 2e34231 commit b988928

File tree

2 files changed

+19
-36
lines changed

2 files changed

+19
-36
lines changed

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,7 +3048,7 @@ class ResolverVisitor extends ScopedVisitor {
30483048
StaticTypeAnalyzer typeAnalyzer;
30493049

30503050
/// The type system in use during resolution.
3051-
TypeSystem typeSystem;
3051+
Dart2TypeSystem typeSystem;
30523052

30533053
/// The class declaration representing the class containing the current node,
30543054
/// or `null` if the current node is not contained in a class.
@@ -4813,12 +4813,10 @@ class ResolverVisitor extends ScopedVisitor {
48134813
DartType uninstantiatedType, TypeArgumentList typeArguments,
48144814
{AstNode errorNode, bool isConst: false}) {
48154815
errorNode ??= inferenceNode;
4816-
TypeSystem ts = typeSystem;
48174816
if (typeArguments == null &&
48184817
uninstantiatedType is FunctionType &&
4819-
uninstantiatedType.typeFormals.isNotEmpty &&
4820-
ts is Dart2TypeSystem) {
4821-
var typeArguments = ts.inferGenericFunctionOrType(
4818+
uninstantiatedType.typeFormals.isNotEmpty) {
4819+
var typeArguments = typeSystem.inferGenericFunctionOrType(
48224820
typeParameters: uninstantiatedType.typeFormals,
48234821
parameters: const <ParameterElement>[],
48244822
declaredReturnType: uninstantiatedType.returnType,
@@ -5862,7 +5860,7 @@ class ToDoFinder {
58625860
///
58635861
/// The client must set [nameScope] before calling [resolveTypeName].
58645862
class TypeNameResolver {
5865-
final TypeSystem typeSystem;
5863+
final Dart2TypeSystem typeSystem;
58665864
final DartType dynamicType;
58675865
final bool isNonNullableUnit;
58685866
final AnalysisOptionsImpl analysisOptions;
@@ -6194,9 +6192,8 @@ class TypeNameResolver {
61946192
}
61956193
} else {
61966194
if (element is GenericTypeAliasElementImpl) {
6197-
var ts = typeSystem as Dart2TypeSystem;
61986195
List<DartType> typeArguments =
6199-
ts.instantiateTypeFormalsToBounds2(element);
6196+
typeSystem.instantiateTypeFormalsToBounds2(element);
62006197
type = GenericTypeAliasElementImpl.typeAfterSubstitution(
62016198
element, typeArguments) ??
62026199
dynamicType;
@@ -6312,17 +6309,15 @@ class TypeNameResolver {
63126309
TypeName node, ClassElement typeElement) {
63136310
AstNode constructorName = node.parent;
63146311
AstNode enclosingConstructor = constructorName?.parent;
6315-
TypeSystem ts = typeSystem;
63166312
if (constructorName is ConstructorName &&
63176313
enclosingConstructor is ConstructorDeclaration &&
6318-
enclosingConstructor.redirectedConstructor == constructorName &&
6319-
ts is Dart2TypeSystem) {
6314+
enclosingConstructor.redirectedConstructor == constructorName) {
63206315
ClassOrMixinDeclaration enclosingClassNode = enclosingConstructor.parent;
63216316
var enclosingClassElement = enclosingClassNode.declaredElement;
63226317
if (enclosingClassElement == typeElement) {
63236318
return typeElement.thisType.typeArguments;
63246319
} else {
6325-
return ts.inferGenericFunctionOrType(
6320+
return typeSystem.inferGenericFunctionOrType(
63266321
typeParameters: typeElement.typeParameters,
63276322
parameters: const [],
63286323
declaredReturnType: typeElement.thisType,
@@ -6441,8 +6436,7 @@ class TypeNameResolver {
64416436
typeArguments =
64426437
_inferTypeArgumentsForRedirectedConstructor(node, element);
64436438
if (typeArguments == null) {
6444-
var ts = typeSystem as Dart2TypeSystem;
6445-
typeArguments = ts.instantiateTypeFormalsToBounds2(element);
6439+
typeArguments = typeSystem.instantiateTypeFormalsToBounds2(element);
64466440
}
64476441
}
64486442

pkg/analyzer/lib/src/generated/static_type_analyzer.dart

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
5252
/**
5353
* The type system in use for static type analysis.
5454
*/
55-
TypeSystem _typeSystem;
55+
Dart2TypeSystem _typeSystem;
5656

5757
/**
5858
* The type representing the type 'dynamic'.
@@ -124,12 +124,11 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
124124
FormalParameterList node, DartType functionType) {
125125
bool inferred = false;
126126
if (node != null && functionType is FunctionType) {
127-
var ts = _typeSystem as Dart2TypeSystem;
128127
void inferType(ParameterElementImpl p, DartType inferredType) {
129128
// Check that there is no declared type, and that we have not already
130129
// inferred a type in some fashion.
131130
if (p.hasImplicitType && (p.type == null || p.type.isDynamic)) {
132-
inferredType = ts.upperBoundForType(inferredType);
131+
inferredType = _typeSystem.upperBoundForType(inferredType);
133132
if (inferredType.isDartCoreNull) {
134133
inferredType = _typeProvider.objectType;
135134
}
@@ -202,8 +201,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
202201
HintCode.INFERENCE_FAILURE_ON_COLLECTION_LITERAL, node, ['List']);
203202
}
204203

205-
var typeArguments =
206-
(_typeSystem as Dart2TypeSystem).inferGenericFunctionOrType(
204+
var typeArguments = _typeSystem.inferGenericFunctionOrType(
207205
typeParameters: typeParameters,
208206
parameters: parameters,
209207
declaredReturnType: element.thisType,
@@ -227,8 +225,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
227225
}
228226

229227
var element = _typeProvider.mapElement;
230-
var typeArguments =
231-
(_typeSystem as Dart2TypeSystem).inferGenericFunctionOrType(
228+
var typeArguments = _typeSystem.inferGenericFunctionOrType(
232229
typeParameters: element.typeParameters,
233230
parameters: const [],
234231
declaredReturnType: element.thisType,
@@ -251,8 +248,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
251248
}
252249

253250
var element = _typeProvider.setElement;
254-
var typeArguments =
255-
(_typeSystem as Dart2TypeSystem).inferGenericFunctionOrType(
251+
var typeArguments = _typeSystem.inferGenericFunctionOrType(
256252
typeParameters: element.typeParameters,
257253
parameters: const [],
258254
declaredReturnType: element.thisType,
@@ -1674,11 +1670,9 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
16741670
ArgumentList argumentList,
16751671
AstNode errorNode,
16761672
{bool isConst: false}) {
1677-
TypeSystem ts = _typeSystem;
16781673
if (typeArguments == null &&
16791674
fnType is FunctionType &&
1680-
fnType.typeFormals.isNotEmpty &&
1681-
ts is Dart2TypeSystem) {
1675+
fnType.typeFormals.isNotEmpty) {
16821676
// Get the parameters that correspond to the uninstantiated generic.
16831677
List<ParameterElement> rawParameters =
16841678
ResolverVisitor.resolveArgumentsToParameters(
@@ -1693,7 +1687,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
16931687
argTypes.add(argumentList.arguments[i].staticType);
16941688
}
16951689
}
1696-
var typeArgs = ts.inferGenericFunctionOrType(
1690+
var typeArgs = _typeSystem.inferGenericFunctionOrType(
16971691
typeParameters: fnType.typeFormals,
16981692
parameters: params,
16991693
declaredReturnType: fnType.returnType,
@@ -1996,12 +1990,9 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
19961990
SimpleIdentifier identifier,
19971991
DartType tearOffType,
19981992
) {
1999-
TypeSystem ts = _typeSystem;
20001993
var context = InferenceContext.getContext(expression);
2001-
if (context is FunctionType &&
2002-
tearOffType is FunctionType &&
2003-
ts is Dart2TypeSystem) {
2004-
var typeArguments = ts.inferFunctionTypeInstantiation(
1994+
if (context is FunctionType && tearOffType is FunctionType) {
1995+
var typeArguments = _typeSystem.inferFunctionTypeInstantiation(
20051996
context,
20061997
tearOffType,
20071998
errorReporter: _resolver.errorReporter,
@@ -2134,8 +2125,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
21342125
argumentTypes[2 * i + 1] = inferredTypes[i].valueType ?? dynamicType;
21352126
}
21362127

2137-
var typeArguments =
2138-
(_typeSystem as Dart2TypeSystem).inferGenericFunctionOrType(
2128+
var typeArguments = _typeSystem.inferGenericFunctionOrType(
21392129
typeParameters: typeParameters,
21402130
parameters: parameters,
21412131
declaredReturnType: element.thisType,
@@ -2166,8 +2156,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
21662156
argumentTypes[i] = inferredTypes[i].elementType ?? dynamicType;
21672157
}
21682158

2169-
var typeArguments =
2170-
(_typeSystem as Dart2TypeSystem).inferGenericFunctionOrType(
2159+
var typeArguments = _typeSystem.inferGenericFunctionOrType(
21712160
typeParameters: typeParameters,
21722161
parameters: parameters,
21732162
declaredReturnType: element.thisType,

0 commit comments

Comments
 (0)