mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:29:48 +00:00
9d933d1281
Tested: No new tests. Change-Id: Idf19ce8b6743b221841e6cef6b2a80e8ab37860e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354260 Auto-Submit: Lasse Nielsen <lrn@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Reviewed-by: Nate Bosch <nbosch@google.com> Reviewed-by: Daco Harkes <dacoharkes@google.com> Commit-Queue: Lasse Nielsen <lrn@google.com>
100 lines
2.6 KiB
Dart
100 lines
2.6 KiB
Dart
// 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.
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
sealed class A {}
|
|
|
|
class B extends A {}
|
|
|
|
class C extends A {}
|
|
|
|
extension type ExtensionTypeList<T>(List<T> it) implements List<T> {}
|
|
|
|
extension type ExtensionTypeMap<K, V>(Map<K, V> it) implements Map<K, V> {
|
|
V method(K key) => it[key]!;
|
|
V get getter => it.values.first;
|
|
void genericMethod<T>(K key, V value, void Function(T) f) {}
|
|
}
|
|
|
|
exhaustiveListExtensionType(ExtensionTypeList<A> list) {
|
|
return switch (list) {
|
|
[] => 0,
|
|
[B()] => 1,
|
|
[C()] => 2,
|
|
[_, _, ...]=> 3,
|
|
};
|
|
}
|
|
|
|
exhaustiveMapExtensionType1(ExtensionTypeMap<int, A> map) {
|
|
return switch (map) {
|
|
Map() => 0,
|
|
};
|
|
}
|
|
|
|
exhaustiveMapExtensionType2(ExtensionTypeMap<int, A> map) {
|
|
return switch (map) {
|
|
Map(isEmpty: true) => 0,
|
|
Map(isEmpty: false) => 1,
|
|
};
|
|
}
|
|
|
|
exhaustiveMapExtensionType3(ExtensionTypeMap<int, A> map) {
|
|
return switch (map) {
|
|
Map() => 0,
|
|
{1: _} => 1,
|
|
// ^^
|
|
// [analyzer] HINT.UNREACHABLE_SWITCH_CASE
|
|
{2: _} => 2,
|
|
// ^^
|
|
// [analyzer] HINT.UNREACHABLE_SWITCH_CASE
|
|
};
|
|
}
|
|
|
|
exhaustiveMapMethod(ExtensionTypeMap<int, A> map) {
|
|
return switch (map) {
|
|
ExtensionTypeMap(:A Function(int) method) => 0,
|
|
};
|
|
}
|
|
|
|
exhaustiveMapGetter(ExtensionTypeMap<int, A> map) {
|
|
return switch (map) {
|
|
ExtensionTypeMap(:B getter) => 0,
|
|
ExtensionTypeMap(:C getter) => 1,
|
|
};
|
|
}
|
|
|
|
exhaustiveMapGenericMethod(ExtensionTypeMap<int, A> map) {
|
|
return switch (map) {
|
|
ExtensionTypeMap(
|
|
:void Function<X>(int, A, void Function(X)) genericMethod) => 0,
|
|
};
|
|
}
|
|
|
|
exhaustiveMapField(ExtensionTypeMap<int, A> map) {
|
|
return switch (map) {
|
|
ExtensionTypeMap(:Map<int, A> it) => 0,
|
|
};
|
|
}
|
|
|
|
main() {
|
|
Expect.equals(0, exhaustiveListExtensionType(ExtensionTypeList([])));
|
|
Expect.equals(2, exhaustiveListExtensionType(ExtensionTypeList([C()])));
|
|
|
|
Expect.equals(0, exhaustiveMapExtensionType1(ExtensionTypeMap({0: B()})));
|
|
|
|
Expect.equals(0, exhaustiveMapExtensionType2(ExtensionTypeMap({})));
|
|
Expect.equals(1, exhaustiveMapExtensionType2(ExtensionTypeMap({0: B()})));
|
|
|
|
Expect.equals(0, exhaustiveMapExtensionType3(ExtensionTypeMap({0: B()})));
|
|
|
|
Expect.equals(0, exhaustiveMapMethod(ExtensionTypeMap({0: B()})));
|
|
|
|
Expect.equals(0, exhaustiveMapGetter(ExtensionTypeMap({0: B()})));
|
|
Expect.equals(1, exhaustiveMapGetter(ExtensionTypeMap({0: C()})));
|
|
|
|
Expect.equals(0, exhaustiveMapGenericMethod(ExtensionTypeMap({0: B()})));
|
|
|
|
Expect.equals(0, exhaustiveMapField(ExtensionTypeMap({0: B()})));
|
|
} |