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>
diff --git a/pkg/analyzer/lib/src/dart/resolver/prefix_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/prefix_expression_resolver.dart
index 62142f1..d16861a 100644
--- a/pkg/analyzer/lib/src/dart/resolver/prefix_expression_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/prefix_expression_resolver.dart
@@ -41,8 +41,6 @@
ErrorReporter get _errorReporter => _resolver.errorReporter;
- bool get _isNonNullableByDefault => _typeSystem.isNonNullableByDefault;
-
TypeProvider get _typeProvider => _resolver.typeProvider;
TypeSystemImpl get _typeSystem => _resolver.typeSystem;
@@ -138,17 +136,6 @@
}
}
- /// Return the non-nullable variant of the [type] if NNBD is enabled, otherwise
- /// return the type itself.
- ///
- /// TODO(scheglov) this is duplicate
- DartType _nonNullable(DartType type) {
- if (_isNonNullableByDefault) {
- return _typeSystem.promoteToNonNull(type);
- }
- return type;
- }
-
/// Record that the static type of the given node is the given type.
///
/// @param expression the node whose type is to be recorded
@@ -227,7 +214,7 @@
// No special handling for incremental operators.
} else if (operator.isIncrementOperator) {
if (node.readType.isDartCoreInt) {
- staticType = _nonNullable(_typeProvider.intType);
+ staticType = _typeProvider.intType;
} else {
_checkForInvalidAssignmentIncDec(node, staticType);
}
@@ -252,7 +239,7 @@
_resolver.boolExpressionVerifier.checkForNonBoolNegationExpression(operand);
- _recordStaticType(node, _nonNullable(_typeProvider.boolType));
+ _recordStaticType(node, _typeProvider.boolType);
_flowAnalysis?.flow?.logicalNot_end(node, operand);
}
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index f05f178..839af0a 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -377,8 +377,8 @@
reportConstEvaluationErrors: reportConstEvaluationErrors,
migratableAstInfoProvider: _migratableAstInfoProvider);
inferenceContext = InferenceContext._(this);
- typeAnalyzer = StaticTypeAnalyzer(
- this, featureSet, _flowAnalysis, migrationResolutionHooks);
+ typeAnalyzer =
+ StaticTypeAnalyzer(this, _flowAnalysis, migrationResolutionHooks);
}
/// Return the element representing the function containing the current node,
diff --git a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
index a06752f..8fb9d81 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -2,7 +2,6 @@
// 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:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
@@ -28,9 +27,6 @@
/// The resolver driving the resolution and type analysis.
final ResolverVisitor _resolver;
- /// The feature set that should be used to resolve types.
- final FeatureSet _featureSet;
-
final MigrationResolutionHooks _migrationResolutionHooks;
/// The object providing access to the types defined by the language.
@@ -48,17 +44,13 @@
/// [_resolver] based on the
///
/// @param resolver the resolver driving this participant
- StaticTypeAnalyzer(this._resolver, this._featureSet, this._flowAnalysis,
- this._migrationResolutionHooks) {
+ StaticTypeAnalyzer(
+ this._resolver, this._flowAnalysis, this._migrationResolutionHooks) {
_typeProvider = _resolver.typeProvider;
_typeSystem = _resolver.typeSystem;
_dynamicType = _typeProvider.dynamicType;
}
- /// Is `true` if the library being analyzed is non-nullable by default.
- bool get _isNonNullableByDefault =>
- _featureSet.isEnabled(Feature.non_nullable);
-
/// Given a constructor for a generic type, returns the equivalent generic
/// function type that we could use to forward to the constructor, or for a
/// non-generic type simply returns the constructor type.
@@ -111,7 +103,7 @@
/// `String`.</blockquote>
@override
void visitAdjacentStrings(AdjacentStrings node) {
- recordStaticType(node, _nonNullable(_typeProvider.stringType));
+ recordStaticType(node, _typeProvider.stringType);
}
/// The Dart Language Specification, 12.32: <blockquote>... the cast expression <i>e as T</i> ...
@@ -140,7 +132,7 @@
/// bool.</blockquote>
@override
void visitBooleanLiteral(BooleanLiteral node) {
- recordStaticType(node, _nonNullable(_typeProvider.boolType));
+ recordStaticType(node, _typeProvider.boolType);
}
/// The Dart Language Specification, 12.15.2: <blockquote>A cascaded method invocation expression
@@ -167,7 +159,7 @@
/// double.</blockquote>
@override
void visitDoubleLiteral(DoubleLiteral node) {
- recordStaticType(node, _nonNullable(_typeProvider.doubleType));
+ recordStaticType(node, _typeProvider.doubleType);
}
@override
@@ -242,9 +234,9 @@
if (context == null ||
_typeSystem.isAssignableTo2(_typeProvider.intType, context) ||
!_typeSystem.isAssignableTo2(_typeProvider.doubleType, context)) {
- recordStaticType(node, _nonNullable(_typeProvider.intType));
+ recordStaticType(node, _typeProvider.intType);
} else {
- recordStaticType(node, _nonNullable(_typeProvider.doubleType));
+ recordStaticType(node, _typeProvider.doubleType);
}
}
@@ -254,7 +246,7 @@
/// The static type of an is-expression is `bool`.</blockquote>
@override
void visitIsExpression(IsExpression node) {
- recordStaticType(node, _nonNullable(_typeProvider.boolType));
+ recordStaticType(node, _typeProvider.boolType);
}
@override
@@ -292,14 +284,14 @@
/// `String`.</blockquote>
@override
void visitSimpleStringLiteral(SimpleStringLiteral node) {
- recordStaticType(node, _nonNullable(_typeProvider.stringType));
+ recordStaticType(node, _typeProvider.stringType);
}
/// The Dart Language Specification, 12.5: <blockquote>The static type of a string literal is
/// `String`.</blockquote>
@override
void visitStringInterpolation(StringInterpolation node) {
- recordStaticType(node, _nonNullable(_typeProvider.stringType));
+ recordStaticType(node, _typeProvider.stringType);
}
@override
@@ -316,7 +308,7 @@
@override
void visitSymbolLiteral(SymbolLiteral node) {
- recordStaticType(node, _nonNullable(_typeProvider.symbolType));
+ recordStaticType(node, _typeProvider.symbolType);
}
/// The Dart Language Specification, 12.10: <blockquote>The static type of `this` is the
@@ -461,13 +453,4 @@
constructor.staticElement = constructorElement;
}
}
-
- /// Return the non-nullable variant of the [type] if NNBD is enabled, otherwise
- /// return the type itself.
- DartType _nonNullable(DartType type) {
- if (_isNonNullableByDefault) {
- return _typeSystem.promoteToNonNull(type);
- }
- return type;
- }
}