diff --git a/pkg/_fe_analyzer_shared/lib/src/exhaustiveness/types/record.dart b/pkg/_fe_analyzer_shared/lib/src/exhaustiveness/types/record.dart index f98bfa619d3..f3809eb18da 100644 --- a/pkg/_fe_analyzer_shared/lib/src/exhaustiveness/types/record.dart +++ b/pkg/_fe_analyzer_shared/lib/src/exhaustiveness/types/record.dart @@ -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 extends TypeBasedStaticType { RecordStaticType(super.typeOperations, super.fieldLookup, super.type) : super(isImplicitlyNullable: false); @@ -29,23 +12,6 @@ class RecordStaticType extends TypeBasedStaticType { @override bool get isRecord => true; - @override - bool isSubtypeOfInternal(StaticType other) { - if (other is! RecordStaticType) { - return false; - } - if (fields.length != other.fields.length) { - return false; - } - for (MapEntry field in fields.entries) { - StaticType? type = other.fields[field.key]; - if (type == null) { - return false; - } - } - return true; - } - @override String spaceToText(Map spaceProperties, Map additionalSpaceProperties) { diff --git a/pkg/_fe_analyzer_shared/test/exhaustiveness/data/issue52800.dart b/pkg/_fe_analyzer_shared/test/exhaustiveness/data/issue52800.dart new file mode 100644 index 00000000000..bc3fe3fead9 --- /dev/null +++ b/pkg/_fe_analyzer_shared/test/exhaustiveness/data/issue52800.dart @@ -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, + };