[_fe_analyzer_shared] Add SharedNullTypeStructure class.

This is the shared base class for all representations of the type
`Null`. This allows the shared codebase to use `is` tests to tell when
a type is `Null`.

Change-Id: I98059b60c7eaab9c9f1e3f7addb7913dffc9cf9d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396380
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
Paul Berry
2024-11-20 14:55:00 +00:00
committed by Commit Queue
parent 0263371cfe
commit f601692dd7
9 changed files with 14 additions and 18 deletions
@@ -208,9 +208,6 @@ abstract interface class TypeAnalyzerOperations<
/// a subtype query, but the implementations can do that more efficiently.
bool isNonNullableInternal(TypeStructure type);
/// Returns `true` if [type] is `Null`.
bool isNullInternal(TypeStructure type);
/// Returns `true` if [type] is `Object` from `dart:core`. The method returns
/// `false` for `Object?` and `Object*`.
bool isObject(SharedTypeView<TypeStructure> type);
@@ -1665,8 +1662,7 @@ abstract class TypeConstraintGenerator<
// If `P` is `Null`, then the match holds under no constraints:
// Only if `Q` is nullable.
if (pNullability == NullabilitySuffix.none &&
typeAnalyzerOperations.isNullInternal(p)) {
if (p is SharedNullTypeStructure) {
return typeAnalyzerOperations.isNullableInternal(q);
}
@@ -66,6 +66,12 @@ abstract interface class SharedNamedTypeStructure<
TypeStructure get type;
}
/// Common interface for data structures used by implementations to represent
/// the type `Null`.
abstract interface class SharedNullTypeStructure<
TypeStructure extends SharedTypeStructure<TypeStructure>>
implements SharedTypeStructure<TypeStructure> {}
/// Common interface for data structures used by the implementations to
/// represent a record type.
abstract interface class SharedRecordTypeStructure<
@@ -2990,9 +2990,6 @@ class MiniAstOperations
unwrappedType.nullabilitySuffix == NullabilitySuffix.none;
}
@override
bool isNullInternal(Type type) => type is NullType;
@override
bool isObject(SharedTypeView<Type> type) {
Type unwrappedType = type.unwrapTypeView();
+2 -1
View File
@@ -480,7 +480,8 @@ class NeverType extends _SpecialSimpleType {
/// Representation of the type `Null` suitable for unit testing of code in the
/// `_fe_analyzer_shared` package.
class NullType extends _SpecialSimpleType {
class NullType extends _SpecialSimpleType
implements SharedNullTypeStructure<Type> {
static final instance = NullType._();
NullType._()
+2 -1
View File
@@ -1142,7 +1142,8 @@ class NeverTypeImpl extends TypeImpl implements NeverType {
/// A concrete implementation of [DartType] representing the type `Null`, with
/// no type parameters and no nullability suffix.
class NullTypeImpl extends InterfaceTypeImpl {
class NullTypeImpl extends InterfaceTypeImpl
implements SharedNullTypeStructure<DartType> {
NullTypeImpl({required super.element, super.alias}) : super._null();
@override
@@ -585,9 +585,6 @@ class TypeSystemOperations
return typeSystem.isNullable(type);
}
@override
bool isNullInternal(DartType type) => type.isDartCoreNull;
@override
bool isObject(SharedTypeView<DartType> type) {
return type.unwrapTypeView().isDartCoreObject &&
@@ -569,9 +569,6 @@ class OperationsCfe
return typeEnvironment.coreTypes.isBottom(type.unwrapTypeView());
}
@override
bool isNullInternal(DartType type) => type is NullType;
@override
// Coverage-ignore(suite): Not run.
bool isObject(SharedTypeView<DartType> type) {
+2 -1
View File
@@ -74,10 +74,11 @@ import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer_operations.
import 'package:_fe_analyzer_shared/src/types/shared_type.dart'
show
SharedDynamicTypeStructure,
SharedNamedFunctionParameterStructure,
SharedFunctionTypeStructure,
SharedInvalidTypeStructure,
SharedNamedFunctionParameterStructure,
SharedNamedTypeStructure,
SharedNullTypeStructure,
SharedRecordTypeStructure,
SharedTypeParameterStructure,
SharedTypeStructure,
+1 -1
View File
@@ -774,7 +774,7 @@ class NeverType extends DartType {
}
}
class NullType extends DartType {
class NullType extends DartType implements SharedNullTypeStructure<DartType> {
@override
final int hashCode = 415324;