Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fe1ed1d

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Remove unnecessary _nonNullable() invocations.
We made TypeProvider legacy or null-safe long time ago, so we already provide correct types. R=brianwilkerson@google.com Change-Id: I3bb7f9c6d8b2292fcb62df1820abbd84d142340d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164720 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent 90ec73c commit fe1ed1d

File tree

3 files changed

+15
-45
lines changed

3 files changed

+15
-45
lines changed

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ class PrefixExpressionResolver {
4141

4242
ErrorReporter get _errorReporter => _resolver.errorReporter;
4343

44-
bool get _isNonNullableByDefault => _typeSystem.isNonNullableByDefault;
45-
4644
TypeProvider get _typeProvider => _resolver.typeProvider;
4745

4846
TypeSystemImpl get _typeSystem => _resolver.typeSystem;
@@ -138,17 +136,6 @@ class PrefixExpressionResolver {
138136
}
139137
}
140138

141-
/// Return the non-nullable variant of the [type] if NNBD is enabled, otherwise
142-
/// return the type itself.
143-
///
144-
/// TODO(scheglov) this is duplicate
145-
DartType _nonNullable(DartType type) {
146-
if (_isNonNullableByDefault) {
147-
return _typeSystem.promoteToNonNull(type);
148-
}
149-
return type;
150-
}
151-
152139
/// Record that the static type of the given node is the given type.
153140
///
154141
/// @param expression the node whose type is to be recorded
@@ -227,7 +214,7 @@ class PrefixExpressionResolver {
227214
// No special handling for incremental operators.
228215
} else if (operator.isIncrementOperator) {
229216
if (node.readType.isDartCoreInt) {
230-
staticType = _nonNullable(_typeProvider.intType);
217+
staticType = _typeProvider.intType;
231218
} else {
232219
_checkForInvalidAssignmentIncDec(node, staticType);
233220
}
@@ -252,7 +239,7 @@ class PrefixExpressionResolver {
252239

253240
_resolver.boolExpressionVerifier.checkForNonBoolNegationExpression(operand);
254241

255-
_recordStaticType(node, _nonNullable(_typeProvider.boolType));
242+
_recordStaticType(node, _typeProvider.boolType);
256243

257244
_flowAnalysis?.flow?.logicalNot_end(node, operand);
258245
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ class ResolverVisitor extends ScopedVisitor {
377377
reportConstEvaluationErrors: reportConstEvaluationErrors,
378378
migratableAstInfoProvider: _migratableAstInfoProvider);
379379
inferenceContext = InferenceContext._(this);
380-
typeAnalyzer = StaticTypeAnalyzer(
381-
this, featureSet, _flowAnalysis, migrationResolutionHooks);
380+
typeAnalyzer =
381+
StaticTypeAnalyzer(this, _flowAnalysis, migrationResolutionHooks);
382382
}
383383

384384
/// Return the element representing the function containing the current node,

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

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/dart/analysis/features.dart';
65
import 'package:analyzer/dart/ast/ast.dart';
76
import 'package:analyzer/dart/ast/visitor.dart';
87
import 'package:analyzer/dart/element/element.dart';
@@ -28,9 +27,6 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
2827
/// The resolver driving the resolution and type analysis.
2928
final ResolverVisitor _resolver;
3029

31-
/// The feature set that should be used to resolve types.
32-
final FeatureSet _featureSet;
33-
3430
final MigrationResolutionHooks _migrationResolutionHooks;
3531

3632
/// The object providing access to the types defined by the language.
@@ -48,17 +44,13 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
4844
/// [_resolver] based on the
4945
///
5046
/// @param resolver the resolver driving this participant
51-
StaticTypeAnalyzer(this._resolver, this._featureSet, this._flowAnalysis,
52-
this._migrationResolutionHooks) {
47+
StaticTypeAnalyzer(
48+
this._resolver, this._flowAnalysis, this._migrationResolutionHooks) {
5349
_typeProvider = _resolver.typeProvider;
5450
_typeSystem = _resolver.typeSystem;
5551
_dynamicType = _typeProvider.dynamicType;
5652
}
5753

58-
/// Is `true` if the library being analyzed is non-nullable by default.
59-
bool get _isNonNullableByDefault =>
60-
_featureSet.isEnabled(Feature.non_nullable);
61-
6254
/// Given a constructor for a generic type, returns the equivalent generic
6355
/// function type that we could use to forward to the constructor, or for a
6456
/// non-generic type simply returns the constructor type.
@@ -111,7 +103,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
111103
/// `String`.</blockquote>
112104
@override
113105
void visitAdjacentStrings(AdjacentStrings node) {
114-
recordStaticType(node, _nonNullable(_typeProvider.stringType));
106+
recordStaticType(node, _typeProvider.stringType);
115107
}
116108

117109
/// The Dart Language Specification, 12.32: <blockquote>... the cast expression <i>e as T</i> ...
@@ -140,7 +132,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
140132
/// bool.</blockquote>
141133
@override
142134
void visitBooleanLiteral(BooleanLiteral node) {
143-
recordStaticType(node, _nonNullable(_typeProvider.boolType));
135+
recordStaticType(node, _typeProvider.boolType);
144136
}
145137

146138
/// The Dart Language Specification, 12.15.2: <blockquote>A cascaded method invocation expression
@@ -167,7 +159,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
167159
/// double.</blockquote>
168160
@override
169161
void visitDoubleLiteral(DoubleLiteral node) {
170-
recordStaticType(node, _nonNullable(_typeProvider.doubleType));
162+
recordStaticType(node, _typeProvider.doubleType);
171163
}
172164

173165
@override
@@ -242,9 +234,9 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
242234
if (context == null ||
243235
_typeSystem.isAssignableTo2(_typeProvider.intType, context) ||
244236
!_typeSystem.isAssignableTo2(_typeProvider.doubleType, context)) {
245-
recordStaticType(node, _nonNullable(_typeProvider.intType));
237+
recordStaticType(node, _typeProvider.intType);
246238
} else {
247-
recordStaticType(node, _nonNullable(_typeProvider.doubleType));
239+
recordStaticType(node, _typeProvider.doubleType);
248240
}
249241
}
250242

@@ -254,7 +246,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
254246
/// The static type of an is-expression is `bool`.</blockquote>
255247
@override
256248
void visitIsExpression(IsExpression node) {
257-
recordStaticType(node, _nonNullable(_typeProvider.boolType));
249+
recordStaticType(node, _typeProvider.boolType);
258250
}
259251

260252
@override
@@ -292,14 +284,14 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
292284
/// `String`.</blockquote>
293285
@override
294286
void visitSimpleStringLiteral(SimpleStringLiteral node) {
295-
recordStaticType(node, _nonNullable(_typeProvider.stringType));
287+
recordStaticType(node, _typeProvider.stringType);
296288
}
297289

298290
/// The Dart Language Specification, 12.5: <blockquote>The static type of a string literal is
299291
/// `String`.</blockquote>
300292
@override
301293
void visitStringInterpolation(StringInterpolation node) {
302-
recordStaticType(node, _nonNullable(_typeProvider.stringType));
294+
recordStaticType(node, _typeProvider.stringType);
303295
}
304296

305297
@override
@@ -316,7 +308,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
316308

317309
@override
318310
void visitSymbolLiteral(SymbolLiteral node) {
319-
recordStaticType(node, _nonNullable(_typeProvider.symbolType));
311+
recordStaticType(node, _typeProvider.symbolType);
320312
}
321313

322314
/// The Dart Language Specification, 12.10: <blockquote>The static type of `this` is the
@@ -461,13 +453,4 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
461453
constructor.staticElement = constructorElement;
462454
}
463455
}
464-
465-
/// Return the non-nullable variant of the [type] if NNBD is enabled, otherwise
466-
/// return the type itself.
467-
DartType _nonNullable(DartType type) {
468-
if (_isNonNullableByDefault) {
469-
return _typeSystem.promoteToNonNull(type);
470-
}
471-
return type;
472-
}
473456
}

0 commit comments

Comments
 (0)