mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
Legacy. Remove star types from more type operations.
Change-Id: I99168c1b2be222b62cbfef600eef1cfbbd9ba55e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356288 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
50fb345709
commit
f1d68ee739
4 changed files with 7 additions and 112 deletions
|
@ -3638,6 +3638,7 @@ abstract class InterfaceElementImpl extends InstanceElementImpl
|
|||
return instance;
|
||||
}
|
||||
case NullabilitySuffix.star:
|
||||
// TODO(scheglov): remove together with `star`
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3655,6 +3656,7 @@ abstract class InterfaceElementImpl extends InstanceElementImpl
|
|||
case NullabilitySuffix.question:
|
||||
_nullableInstance = result;
|
||||
case NullabilitySuffix.star:
|
||||
// TODO(scheglov): remove together with `star`
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,10 +69,8 @@ class NormalizeHelper {
|
|||
}
|
||||
|
||||
// * if S is Object then S
|
||||
// * if S is Object* then S
|
||||
if (S.isDartCoreObject) {
|
||||
if (S_nullability == NullabilitySuffix.none ||
|
||||
S_nullability == NullabilitySuffix.star) {
|
||||
if (S_nullability == NullabilitySuffix.none) {
|
||||
return S;
|
||||
}
|
||||
}
|
||||
|
@ -126,11 +124,6 @@ class NormalizeHelper {
|
|||
return _nullabilityQuestion(T);
|
||||
}
|
||||
|
||||
// NORM(T*)
|
||||
if (T_nullability == NullabilitySuffix.star) {
|
||||
return _nullabilityStar(T);
|
||||
}
|
||||
|
||||
assert(T_nullability == NullabilitySuffix.none);
|
||||
|
||||
// NORM(X extends T)
|
||||
|
@ -201,52 +194,11 @@ class NormalizeHelper {
|
|||
}
|
||||
}
|
||||
|
||||
// * if S is FutureOr<R>* and R is nullable then FutureOr<R>
|
||||
if (S_nullability == NullabilitySuffix.star &&
|
||||
S is InterfaceType &&
|
||||
S.isDartAsyncFutureOr) {
|
||||
var R = S.typeArguments[0];
|
||||
if (typeSystem.isNullable(R)) {
|
||||
return typeProvider.futureOrElement.instantiate(
|
||||
typeArguments: [R],
|
||||
nullabilitySuffix: NullabilitySuffix.none,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// * if S is R? then R?
|
||||
// * if S is R* then R?
|
||||
// * else S?
|
||||
return (S as TypeImpl).withNullability(NullabilitySuffix.question);
|
||||
}
|
||||
|
||||
/// NORM(T*)
|
||||
DartType _nullabilityStar(DartType T) {
|
||||
// * let S be NORM(T)
|
||||
var T_none = (T as TypeImpl).withNullability(NullabilitySuffix.none);
|
||||
var S = _normalize(T_none);
|
||||
var S_nullability = S.nullabilitySuffix;
|
||||
|
||||
// * if S is a top type then S
|
||||
if (typeSystem.isTop(S)) {
|
||||
return S;
|
||||
}
|
||||
|
||||
// * if S is Null then Null
|
||||
if (S_nullability == NullabilitySuffix.none && S.isDartCoreNull) {
|
||||
return typeSystem.nullNone;
|
||||
}
|
||||
|
||||
// * if S is R? then R?
|
||||
if (S_nullability == NullabilitySuffix.question) {
|
||||
return S;
|
||||
}
|
||||
|
||||
// * if S is R* then R*
|
||||
// * else S*
|
||||
return (S as TypeImpl).withNullability(NullabilitySuffix.star);
|
||||
}
|
||||
|
||||
/// NORM(X & T)
|
||||
/// NORM(X extends T)
|
||||
DartType _typeParameterType(TypeParameterTypeImpl T) {
|
||||
|
|
|
@ -176,13 +176,7 @@ class RuntimeTypeEqualityVisitor
|
|||
}
|
||||
|
||||
bool _compatibleNullability(DartType T1, DartType T2) {
|
||||
var T1_nullability = T1.nullabilitySuffix;
|
||||
var T2_nullability = T2.nullabilitySuffix;
|
||||
return T1_nullability == T2_nullability ||
|
||||
T1_nullability == NullabilitySuffix.star &&
|
||||
T2_nullability == NullabilitySuffix.none ||
|
||||
T2_nullability == NullabilitySuffix.star &&
|
||||
T1_nullability == NullabilitySuffix.none;
|
||||
return T1.nullabilitySuffix == T2.nullabilitySuffix;
|
||||
}
|
||||
|
||||
/// Determines if the two lists of type parameters are equal. If they are,
|
||||
|
|
|
@ -6,14 +6,12 @@ import 'package:analyzer/dart/element/element.dart';
|
|||
import 'package:analyzer/dart/element/nullability_suffix.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/src/dart/element/element.dart';
|
||||
import 'package:analyzer/src/dart/element/extensions.dart';
|
||||
import 'package:analyzer/src/dart/element/type.dart';
|
||||
import 'package:analyzer/src/dart/element/type_algebra.dart';
|
||||
import 'package:analyzer/src/dart/element/type_provider.dart';
|
||||
import 'package:analyzer/src/dart/element/type_schema.dart';
|
||||
import 'package:analyzer/src/dart/element/type_system.dart';
|
||||
import 'package:analyzer/src/dart/resolver/variance.dart';
|
||||
import 'package:analyzer/src/generated/utilities_dart.dart';
|
||||
|
||||
/// Helper for checking the subtype relation.
|
||||
///
|
||||
|
@ -104,13 +102,6 @@ class SubtypeHelper {
|
|||
T0.isDartAsyncFutureOr) {
|
||||
return isSubtypeOf(T0.typeArguments[0], T1);
|
||||
}
|
||||
// * if `T0` is `S*` for any `S`, then `T0 <: T1` iff `S <: T1`
|
||||
if (T0_nullability == NullabilitySuffix.star) {
|
||||
return isSubtypeOf(
|
||||
T0.withNullability(NullabilitySuffix.none),
|
||||
T1,
|
||||
);
|
||||
}
|
||||
// * if `T0` is `Null`, `dynamic`, `void`, or `S?` for any `S`,
|
||||
// then the subtyping does not hold, the result is false.
|
||||
if (T0_nullability == NullabilitySuffix.none && T0.isDartCoreNull ||
|
||||
|
@ -143,10 +134,9 @@ class SubtypeHelper {
|
|||
var S = T1.typeArguments[0];
|
||||
return isSubtypeOf(_nullNone, S);
|
||||
}
|
||||
// If `T1` is `Null`, `S?` or `S*` for some `S`, then the query is true.
|
||||
// If `T1` is `Null` or `S?` for some `S`, then the query is true.
|
||||
if (T1_nullability == NullabilitySuffix.none && T1.isDartCoreNull ||
|
||||
T1_nullability == NullabilitySuffix.question ||
|
||||
T1_nullability == NullabilitySuffix.star) {
|
||||
T1_nullability == NullabilitySuffix.question) {
|
||||
return true;
|
||||
}
|
||||
// * if `T1` is a type variable (promoted or not) the query is false
|
||||
|
@ -157,23 +147,6 @@ class SubtypeHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Left Legacy if `T0` is `S0*` then:
|
||||
if (T0_nullability == NullabilitySuffix.star) {
|
||||
// * `T0 <: T1` iff `S0 <: T1`.
|
||||
var S0 = T0.withNullability(NullabilitySuffix.none);
|
||||
return isSubtypeOf(S0, T1);
|
||||
}
|
||||
|
||||
// Right Legacy `T1` is `S1*` then:
|
||||
// * `T0 <: T1` iff `T0 <: S1?`.
|
||||
if (T1_nullability == NullabilitySuffix.star) {
|
||||
if (T1 is FunctionType && _isFunctionTypeWithNamedRequired(T0)) {
|
||||
T1 = _functionTypeWithNamedRequired(T1 as FunctionType);
|
||||
}
|
||||
var S1 = T1.withNullability(NullabilitySuffix.question);
|
||||
return isSubtypeOf(T0, S1);
|
||||
}
|
||||
|
||||
// Left FutureOr: if `T0` is `FutureOr<S0>` then:
|
||||
if (T0_nullability == NullabilitySuffix.none &&
|
||||
T0 is InterfaceTypeImpl &&
|
||||
|
@ -417,9 +390,7 @@ class SubtypeHelper {
|
|||
if (gParameter.isNamed) {
|
||||
var compareNames = fParameter.name.compareTo(gParameter.name);
|
||||
if (compareNames == 0) {
|
||||
var gIsRequiredOrLegacy = gParameter.isRequiredNamed ||
|
||||
g.nullabilitySuffix == NullabilitySuffix.star;
|
||||
if (fParameter.isRequiredNamed && !gIsRequiredOrLegacy) {
|
||||
if (fParameter.isRequiredNamed && !gParameter.isRequiredNamed) {
|
||||
return false;
|
||||
} else if (isSubtypeOf(gParameter.type, fParameter.type)) {
|
||||
fIndex++;
|
||||
|
@ -536,28 +507,4 @@ class SubtypeHelper {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
static FunctionTypeImpl _functionTypeWithNamedRequired(FunctionType type) {
|
||||
return FunctionTypeImpl(
|
||||
typeFormals: type.typeFormals,
|
||||
parameters: type.parameters.map((e) {
|
||||
if (e.isNamed) {
|
||||
return e.copyWith(
|
||||
kind: ParameterKind.NAMED_REQUIRED,
|
||||
);
|
||||
} else {
|
||||
return e;
|
||||
}
|
||||
}).toList(growable: false),
|
||||
returnType: type.returnType,
|
||||
nullabilitySuffix: type.nullabilitySuffix,
|
||||
);
|
||||
}
|
||||
|
||||
static bool _isFunctionTypeWithNamedRequired(DartType type) {
|
||||
if (type is FunctionType) {
|
||||
return type.parameters.any((e) => e.isRequiredNamed);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue