Remove unnecessary getStaticType().
Change-Id: Ic727d2607999aa97a290345c22993cd2ba703d1a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164721
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart
index e16e7da..2564ef7 100644
--- a/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart
@@ -106,15 +106,6 @@
);
}
- /// Return the static type of the given [expression] that is to be used for
- /// type analysis.
- ///
- /// TODO(scheglov) this is duplicate
- DartType _getStaticType(Expression expression) {
- DartType type = expression.staticType;
- return _resolveTypeParameter(type);
- }
-
void _resolveEqual(BinaryExpressionImpl node, {@required bool notEqual}) {
var left = node.leftOperand;
left.accept(_resolver);
@@ -303,7 +294,8 @@
return;
}
- var leftType = _getStaticType(leftOperand);
+ var leftType = leftOperand.staticType;
+ leftType = _resolveTypeParameter(leftType);
if (identical(leftType, NeverTypeImpl.instance)) {
_resolver.errorReporter.reportErrorForNode(
@@ -345,16 +337,21 @@
}
void _resolveUserDefinableType(BinaryExpressionImpl node) {
- if (identical(node.leftOperand.staticType, NeverTypeImpl.instance)) {
+ var leftOperand = node.leftOperand;
+
+ var leftType = leftOperand.staticType;
+ leftType = _resolveTypeParameter(leftType);
+
+ if (identical(leftType, NeverTypeImpl.instance)) {
_inferenceHelper.recordStaticType(node, NeverTypeImpl.instance);
return;
}
DartType staticType =
node.staticInvokeType?.returnType ?? DynamicTypeImpl.instance;
- if (node.leftOperand is! ExtensionOverride) {
+ if (leftOperand is! ExtensionOverride) {
staticType = _typeSystem.refineBinaryExpressionType(
- _getStaticType(node.leftOperand),
+ leftType,
node.operator.type,
node.rightOperand.staticType,
staticType,
diff --git a/pkg/analyzer/lib/src/error/return_type_verifier.dart b/pkg/analyzer/lib/src/error/return_type_verifier.dart
index 9d78748..af65202 100644
--- a/pkg/analyzer/lib/src/error/return_type_verifier.dart
+++ b/pkg/analyzer/lib/src/error/return_type_verifier.dart
@@ -152,7 +152,7 @@
// `T` is the declared return type.
// `S` is the static type of the expression.
var T = enclosingExecutable.returnType;
- var S = getStaticType(expression);
+ var S = expression.staticType;
void reportTypeError() {
if (enclosingExecutable.isClosure) {
@@ -253,7 +253,7 @@
// `T` is the declared return type.
// `S` is the static type of the expression.
var T = enclosingExecutable.returnType;
- var S = getStaticType(expression);
+ var S = expression.staticType;
void reportTypeError() {
if (enclosingExecutable.isClosure) {
@@ -398,19 +398,6 @@
return _typeSystem.isSubtypeOf2(lowerBound, returnType);
}
- /// Return the static type of the given [expression] that is to be used for
- /// type analysis.
- ///
- /// TODO(scheglov) this is duplicate
- static DartType getStaticType(Expression expression) {
- DartType type = expression.staticType;
- if (type == null) {
- // TODO(brianwilkerson) This should never happen.
- return DynamicTypeImpl.instance;
- }
- return type;
- }
-
static bool _isVoidDynamic(DartType type) {
return type.isVoid || type.isDynamic;
}
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 9955b67..15a37c0 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -1564,7 +1564,7 @@
void _checkForArgumentTypeNotAssignableWithExpectedTypes(
Expression expression, DartType expectedStaticType, ErrorCode errorCode) {
_checkForArgumentTypeNotAssignable(
- expression, expectedStaticType, getStaticType(expression), errorCode);
+ expression, expectedStaticType, expression.staticType, errorCode);
}
/// Verify that the arguments in the given [argumentList] can be assigned to
@@ -1586,7 +1586,7 @@
bool _checkForAssignableExpression(
Expression expression, DartType expectedStaticType, ErrorCode errorCode) {
- DartType actualStaticType = getStaticType(expression);
+ DartType actualStaticType = expression.staticType;
return actualStaticType != null &&
_checkForAssignableExpressionAtType(
expression, actualStaticType, expectedStaticType, errorCode);
@@ -2269,7 +2269,7 @@
return false;
}
- DartType iterableType = getStaticType(node.iterable);
+ DartType iterableType = node.iterable.staticType;
// TODO(scheglov) use NullableDereferenceVerifier
if (_isNonNullableByDefault) {
@@ -2507,7 +2507,7 @@
return;
}
// test the static type of the expression
- DartType staticType = getStaticType(expression);
+ DartType staticType = expression.staticType;
if (staticType == null) {
return;
}
@@ -2948,7 +2948,7 @@
} else {
VariableElement leftVariableElement = getVariableElement(lhs);
leftType = (leftVariableElement == null)
- ? getStaticType(lhs)
+ ? lhs.staticType
: leftVariableElement.type;
}
@@ -3114,7 +3114,7 @@
void _checkForMissingEnumConstantInSwitch(SwitchStatement statement) {
// TODO(brianwilkerson) This needs to be checked after constant values have
// been computed.
- var expressionType = getStaticType(statement.expression);
+ var expressionType = statement.expression.staticType;
var hasCaseNull = false;
if (expressionType is InterfaceType) {
@@ -4121,7 +4121,7 @@
}
// prepare 'switch' expression type
- DartType expressionType = getStaticType(expression);
+ DartType expressionType = expression.staticType;
if (expressionType == null) {
return;
}
@@ -4134,7 +4134,7 @@
}
Expression caseExpression = switchCase.expression;
- DartType caseType = getStaticType(caseExpression);
+ DartType caseType = caseExpression.staticType;
// check types
if (!_typeSystem.isAssignableTo2(expressionType, caseType)) {
@@ -5302,17 +5302,6 @@
return fields.toList();
}
- /// Return the static type of the given [expression] that is to be used for
- /// type analysis.
- static DartType getStaticType(Expression expression) {
- DartType type = expression.staticType;
- if (type == null) {
- // TODO(brianwilkerson) This should never happen.
- return DynamicTypeImpl.instance;
- }
- return type;
- }
-
/// Return the variable element represented by the given [expression], or
/// `null` if there is no such element.
static VariableElement getVariableElement(Expression expression) {
diff --git a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
index 8fb9d81..6a45033 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -123,7 +123,7 @@
/// the static type of e.
@override
void visitAwaitExpression(AwaitExpression node) {
- DartType resultType = _getStaticType(node.expression);
+ DartType resultType = node.expression.staticType;
if (resultType != null) resultType = _typeSystem.flatten(resultType);
recordStaticType(node, resultType);
}
@@ -140,7 +140,7 @@
/// t;}(e)</i>.</blockquote>
@override
void visitCascadeExpression(CascadeExpression node) {
- recordStaticType(node, _getStaticType(node.target));
+ recordStaticType(node, node.target.staticType);
}
/// The Dart Language Specification, 12.19: <blockquote> ... a conditional expression <i>c</i> of
@@ -257,7 +257,7 @@
@override
void visitNamedExpression(NamedExpression node) {
Expression expression = node.expression;
- recordStaticType(node, _getStaticType(expression));
+ recordStaticType(node, expression.staticType);
}
/// The Dart Language Specification, 12.2: <blockquote>The static type of `null` is bottom.
@@ -270,7 +270,7 @@
@override
void visitParenthesizedExpression(ParenthesizedExpression node) {
Expression expression = node.expression;
- recordStaticType(node, _getStaticType(expression));
+ recordStaticType(node, expression.staticType);
}
/// The Dart Language Specification, 12.9: <blockquote>The static type of a rethrow expression is
@@ -360,32 +360,6 @@
recordStaticType(node, staticType);
}
- /// Return the static type of the given [expression].
- DartType _getStaticType(Expression expression, {bool read = false}) {
- DartType type;
- if (read) {
- type = expression.staticType;
- } else {
- if (expression is SimpleIdentifier && expression.inSetterContext()) {
- var element = expression.staticElement;
- if (element is PromotableElement) {
- // We're writing to the element so ignore promotions.
- type = element.type;
- } else {
- type = expression.staticType;
- }
- } else {
- type = expression.staticType;
- }
- }
- if (type == null) {
- // TODO(brianwilkerson) Determine the conditions for which the static type
- // is null.
- return _dynamicType;
- }
- return type;
- }
-
/// Return the type represented by the given type [annotation].
DartType _getType(TypeAnnotation annotation) {
DartType type = annotation.type;