Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: pkg/analyzer/lib/src/generated/type_system.dart

Issue 3012593002: Add a hint on static uses of fuzzy arrows. (Closed)
Patch Set: Increment DATA_VERSION Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/generated/type_system.dart
diff --git a/pkg/analyzer/lib/src/generated/type_system.dart b/pkg/analyzer/lib/src/generated/type_system.dart
index 1ed098dd935d46568487bf3b8e8d3eba1d188225..931764d34e980e325562a41500e5ecc214a00a01 100644
--- a/pkg/analyzer/lib/src/generated/type_system.dart
+++ b/pkg/analyzer/lib/src/generated/type_system.dart
@@ -47,6 +47,8 @@ typedef bool _GuardedSubtypeChecker<T>(T t1, T t2, Set<TypeImpl> visitedTypes);
class StrongTypeSystemImpl extends TypeSystem {
static bool _comparingTypeParameterBounds = false;
+ bool allowDynamicAsBottom = true;
+
/**
* True if declaration casts should be allowed, otherwise false.
*
@@ -135,6 +137,8 @@ class StrongTypeSystemImpl extends TypeSystem {
/// Computes the greatest lower bound of [type1] and [type2].
DartType getGreatestLowerBound(DartType type1, DartType type2,
{dynamicIsBottom: false}) {
+ dynamicIsBottom = dynamicIsBottom && allowDynamicAsBottom;
+
// The greatest lower bound relation is reflexive.
if (identical(type1, type2)) {
return type1;
@@ -211,6 +215,8 @@ class StrongTypeSystemImpl extends TypeSystem {
@override
DartType getLeastUpperBound(DartType type1, DartType type2,
{bool dynamicIsBottom: false}) {
+ dynamicIsBottom = dynamicIsBottom && allowDynamicAsBottom;
+
if (isNullableType(type1) && isNonNullableType(type2)) {
assert(type2 is InterfaceType);
type2 = getLeastNullableSupertype(type2 as InterfaceType);
@@ -476,7 +482,8 @@ class StrongTypeSystemImpl extends TypeSystem {
if (t is FunctionType) {
if (!_isTop(t.returnType) ||
- anyParameterType(t, (pt) => !_isBottom(pt, dynamicIsBottom: true))) {
+ anyParameterType(t,
+ (pt) => !_isBottom(pt, dynamicIsBottom: allowDynamicAsBottom))) {
return false;
} else {
return true;
@@ -645,7 +652,8 @@ class StrongTypeSystemImpl extends TypeSystem {
DartType paramType;
if (fType != null && gType != null) {
// If both functions have this parameter, include both of their types.
- paramType = getLeastUpperBound(fType, gType, dynamicIsBottom: true);
+ paramType = getLeastUpperBound(fType, gType,
+ dynamicIsBottom: allowDynamicAsBottom);
} else {
paramType = fType ?? gType;
}
@@ -727,7 +735,7 @@ class StrongTypeSystemImpl extends TypeSystem {
@override
DartType _functionParameterBound(DartType f, DartType g) =>
- getGreatestLowerBound(f, g, dynamicIsBottom: true);
+ getGreatestLowerBound(f, g, dynamicIsBottom: allowDynamicAsBottom);
/// Given a type return its name prepended with the URI to its containing
/// library and separated by a comma.
@@ -811,7 +819,7 @@ class StrongTypeSystemImpl extends TypeSystem {
return FunctionTypeImpl.relate(f1, f2, isSubtypeOf, instantiateToBounds,
parameterRelation: (p1, p2) => _isSubtypeOf(
p2.type, p1.type, visitedTypes,
- dynamicIsBottom: true));
+ dynamicIsBottom: allowDynamicAsBottom));
}
bool _isInterfaceSubtypeOf(
@@ -870,6 +878,8 @@ class StrongTypeSystemImpl extends TypeSystem {
bool _isSubtypeOf(DartType t1, DartType t2, Set<TypeImpl> visitedTypes,
{bool dynamicIsBottom: false}) {
+ dynamicIsBottom = dynamicIsBottom && allowDynamicAsBottom;
+
if (identical(t1, t2)) {
return true;
}
@@ -980,6 +990,8 @@ class StrongTypeSystemImpl extends TypeSystem {
DartType _substituteForUnknownType(DartType type,
{bool lowerBound: false, dynamicIsBottom: false}) {
+ dynamicIsBottom = dynamicIsBottom && allowDynamicAsBottom;
+
if (identical(type, UnknownInferredType.instance)) {
if (lowerBound && !dynamicIsBottom) {
// TODO(jmesserly): this should be the bottom type, once i can be
@@ -1003,7 +1015,7 @@ class StrongTypeSystemImpl extends TypeSystem {
// Parameters are contravariant, so flip the constraint direction.
// Also pass dynamicIsBottom, because this is a fuzzy arrow.
var newType = _substituteForUnknownType(p.type,
- lowerBound: !lowerBound, dynamicIsBottom: true);
+ lowerBound: !lowerBound, dynamicIsBottom: allowDynamicAsBottom);
return new ParameterElementImpl.synthetic(
p.name, newType, p.parameterKind);
});

Powered by Google App Engine
This is Rietveld 408576698