mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
[_fe_analyzer_shared] Remove RecordStaticType.isSubtypeOfInternal
This method caused invalid exhaustiveness checking by seeing record types as related based solely on the structure. The original purpose of the methods has been removed in the mean time by the change to restrict the created spaces by the matched value type. Closes #52800 Change-Id: I8fb581374a4813dc63261d9e1354c4eea94f212c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312982 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Paul Berry <paulberry@google.com>
This commit is contained in:
parent
ab2d19c93d
commit
0d47ba6890
|
@ -5,23 +5,6 @@
|
|||
part of '../types.dart';
|
||||
|
||||
/// [StaticType] for a record type.
|
||||
///
|
||||
/// This models that type aspect of the record using only the structure of the
|
||||
/// record type. This means that the type for `(Object, String)` and
|
||||
/// `(String, int)` will be subtypes of each other.
|
||||
///
|
||||
/// This is necessary to avoid invalid conclusions on the disjointness of
|
||||
/// spaces base on the their types. For instance in
|
||||
///
|
||||
/// method((String, Object) o) {
|
||||
/// if (o case (Object _, String s)) {}
|
||||
/// }
|
||||
///
|
||||
/// the case is not empty even though `(String, Object)` and `(Object, String)`
|
||||
/// are not related type-wise.
|
||||
///
|
||||
/// Not that the fields of the record types _are_ using the type, so that
|
||||
/// the `$1` field of `(String, Object)` is known to contain only `String`s.
|
||||
class RecordStaticType<Type extends Object> extends TypeBasedStaticType<Type> {
|
||||
RecordStaticType(super.typeOperations, super.fieldLookup, super.type)
|
||||
: super(isImplicitlyNullable: false);
|
||||
|
@ -29,23 +12,6 @@ class RecordStaticType<Type extends Object> extends TypeBasedStaticType<Type> {
|
|||
@override
|
||||
bool get isRecord => true;
|
||||
|
||||
@override
|
||||
bool isSubtypeOfInternal(StaticType other) {
|
||||
if (other is! RecordStaticType<Type>) {
|
||||
return false;
|
||||
}
|
||||
if (fields.length != other.fields.length) {
|
||||
return false;
|
||||
}
|
||||
for (MapEntry<Key, StaticType> field in fields.entries) {
|
||||
StaticType? type = other.fields[field.key];
|
||||
if (type == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
String spaceToText(Map<Key, Space> spaceProperties,
|
||||
Map<Key, Space> additionalSpaceProperties) {
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
enum MyEnum { first, second }
|
||||
|
||||
typedef MyData = (
|
||||
MyEnum field1,
|
||||
MyEnum field2,
|
||||
);
|
||||
|
||||
void main() {
|
||||
print(myFn(MyEnum.first, null));
|
||||
print(myFn(MyEnum.first, MyEnum.second));
|
||||
}
|
||||
|
||||
MyData? myFn(MyEnum field1, MyEnum? field2) {
|
||||
return /*type=(MyEnum, MyEnum?)*/
|
||||
switch ((field1, field2)) {
|
||||
final MyData a /*space=(MyEnum, MyEnum)*/
|
||||
=>
|
||||
a,
|
||||
_ /*space=(MyEnum, MyEnum?)*/
|
||||
=>
|
||||
null,
|
||||
};
|
||||
}
|
||||
|
||||
method(
|
||||
(
|
||||
String,
|
||||
Object
|
||||
) o) => /*
|
||||
fields={$1:String,$2:Object},
|
||||
type=(String, Object)
|
||||
*/
|
||||
switch (o) {
|
||||
(Object _, String s) /*space=(String, String)*/ => 0,
|
||||
_ /*space=(String, Object)*/ => 1,
|
||||
};
|
Loading…
Reference in a new issue