Add Never*, use it in type provider etc
Change-Id: I8b7496a56d0479bdbcee3fd8a6e8937aeff8bb10
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105471
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
diff --git a/pkg/analyzer/lib/src/dart/element/type.dart b/pkg/analyzer/lib/src/dart/element/type.dart
index de53916..8da95fd 100644
--- a/pkg/analyzer/lib/src/dart/element/type.dart
+++ b/pkg/analyzer/lib/src/dart/element/type.dart
@@ -68,6 +68,18 @@
new BottomTypeImpl._(NullabilitySuffix.question);
/**
+ * The unique instance of this class, starred.
+ *
+ * This behaves like a version of the Null* type that could be conceivably
+ * migrated to be of type Never. Therefore, it's the bottom of all legacy
+ * types, and also assignable to the true bottom. Note that Never? and Never*
+ * are not the same type, as Never* is a subtype of Never, while Never? is
+ * not.
+ */
+ static final BottomTypeImpl instanceLegacy =
+ new BottomTypeImpl._(NullabilitySuffix.star);
+
+ /**
* The unique instance of this class, non-nullable.
*/
static final BottomTypeImpl instance =
@@ -145,14 +157,7 @@
case NullabilitySuffix.question:
return instanceNullable;
case NullabilitySuffix.star:
- // This should never happen. Converting `Never` to a legacy type should
- // yield `Null`, because prior to NNBD, `Null` was at the bottom of the
- // type hierarchy.
- //
- // However, due to bugs elsewhere in the analyzer, this does still
- // happen sometimes, so for now just coerce to `Never?`.
- // TODO(paulberry): change this to throw an exception.
- return instanceNullable;
+ return instanceLegacy;
case NullabilitySuffix.none:
return instance;
}
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 0814e4c..b5b6b72 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -3404,6 +3404,9 @@
}
@override
+ DartType get bottomType => BottomTypeImpl.instance;
+
+ @override
InterfaceType _getType(Namespace namespace, String typeName) {
InterfaceType type = super._getType(namespace, typeName);
if (type == null) {
@@ -7437,7 +7440,7 @@
InterfaceType get boolType => _boolType;
@override
- DartType get bottomType => BottomTypeImpl.instance;
+ DartType get bottomType => BottomTypeImpl.instanceLegacy;
@override
InterfaceType get deprecatedType => _deprecatedType;
diff --git a/pkg/analyzer/lib/src/generated/type_system.dart b/pkg/analyzer/lib/src/generated/type_system.dart
index f3dce0d..7b41701 100644
--- a/pkg/analyzer/lib/src/generated/type_system.dart
+++ b/pkg/analyzer/lib/src/generated/type_system.dart
@@ -170,7 +170,8 @@
}
// No subtype relation, so no known GLB.
- return typeProvider.bottomType;
+ // TODO(mfairhurst): implement fully NNBD GLB, and return Never (non-legacy)
+ return BottomTypeImpl.instanceLegacy;
}
/**
@@ -2153,7 +2154,7 @@
/// Returns a non-nullable version of [type]. This is equivalent to the
/// operation `NonNull` defined in the spec.
DartType promoteToNonNull(TypeImpl type) {
- if (type.isDartCoreNull) return typeProvider.bottomType;
+ if (type.isDartCoreNull) return BottomTypeImpl.instance;
// TODO(mfairhurst): handle type parameter types
return type.withNullability(NullabilitySuffix.none);
}
diff --git a/pkg/analyzer/lib/src/summary/summary_sdk.dart b/pkg/analyzer/lib/src/summary/summary_sdk.dart
index 516ca6b..e54f587 100644
--- a/pkg/analyzer/lib/src/summary/summary_sdk.dart
+++ b/pkg/analyzer/lib/src/summary/summary_sdk.dart
@@ -148,7 +148,7 @@
}
@override
- DartType get bottomType => BottomTypeImpl.instance;
+ DartType get bottomType => BottomTypeImpl.instanceLegacy;
@override
InterfaceType get deprecatedType {