Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2435. Fix roll failures #2437

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@
/// @author sgrekhov22@gmail.com

class F {
external factory F(num x) = C;
// ^
external factory F() = C;
// ^
// [analyzer] unspecified
// [cfe] unspecified

external factory F.f1(num x) = C.f1;
// ^
external factory F.f1() = C.f1;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

class C implements F {
num x;

external C(this.x);
C.f1(this.x);
external C();
C.f1();
}

enum E {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/// null object.
/// @author sgrekhov22@gmail.com

// Requirements=nnbd-strong

import "../../../../Utils/expect.dart";

class C {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ String testExpression1(ET1 e) =>
E.c => "c"
};

String testExpression2(ET2<num> e) =>
String testExpression2(ET2 e) =>
switch (e) {
E.a => "a",
E.b => "b",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ extension type ET1<T>(E<T> _) {}
extension type ET2<T>(E<T> _) implements E<T> {}

String testStatement1<T extends num>(ET1<T> e) {
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
switch (e) {
//^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
eernstg marked this conversation as resolved.
Show resolved Hide resolved
case E.a:
return "a";
Expand All @@ -34,9 +35,10 @@ String testStatement1<T extends num>(ET1<T> e) {
}

String testStatement2<T extends num>(ET2<T> e) {
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
switch (e) {
//^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
case E.a:
return "a";
Expand Down Expand Up @@ -64,19 +66,21 @@ String testExpression2<T extends num>(ET2<T> e) =>
};

String testStatement3(ET1<num> e) {
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
switch (e) {
//^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
case E.a:
return "ok";
}
}

String testStatement4(ET2<num> e) {
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
switch (e) {
//^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
case E.a:
return "ok";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ extension type ET1(E _) {}
extension type ET2(E _) implements E {}

String testStatement1(ET1 e) {
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
switch (e) {
//^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
case E.a:
return "a";
Expand All @@ -32,9 +33,10 @@ String testStatement1(ET1 e) {
}

String testStatement2(ET2 e) {
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
switch (e) {
//^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
case E.a:
return "a";
Expand Down
24 changes: 3 additions & 21 deletions LanguageFeatures/Extension-types/exhaustiveness_map_A02_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ String test1_2(ET2<bool, bool> m) =>
Map() => "other"
};

String test2_1(ET1<bool, bool> m) {
switch (m) {
case {true: true}:
return "case-1";
case {true: false}:
return "case-2";
case {false: true}:
return "case-3";
case {false: false}:
return "case-4";
case Map():
return "other";
}
}

String test2_2(ET2<bool, bool> m) {
switch (m) {
case {true: true}:
Expand All @@ -68,14 +53,11 @@ String test2_2(ET2<bool, bool> m) {
main() {
Expect.equals("case-1", test1_1(ET1({true: true})));
Expect.equals("case-2", test1_2(ET2({true: false})));
Expect.equals("case-3", test2_1(ET1({false: true})));
Expect.equals("case-4", test2_2(ET2({false: false})));
Expect.equals("other", test1_1(ET1<bool, bool>({})));
Expect.equals("other", test1_2(ET2<bool, bool>({})));
Expect.equals("other", test2_1(ET1<bool, bool>({})));
Expect.equals("other", test2_2(ET2<bool, bool>({})));
Expect.equals("other", test1_1(ET1({true: true, false: false})));
Expect.equals("other", test1_2(ET2({true: false, false: false})));
Expect.equals("other", test2_1(ET1({false: true, true: true})));
Expect.equals("other", test2_2(ET2({false: false, true: true})));
Expect.equals("case-1", test1_1(ET1({true: true, false: false})));
Expect.equals("case-2", test1_2(ET2({true: false, false: false})));
Expect.equals("case-1", test2_2(ET2({false: false, true: true})));
}
37 changes: 37 additions & 0 deletions LanguageFeatures/Extension-types/exhaustiveness_map_A02_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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.

/// @assertion Exhaustiveness with map patterns can only be achieved when there
/// is an exhaustive pattern in addition to any map patterns
///
/// @description Check that a switch statement with a value type an extension
/// type with a `Map` as a representation type but which doesn't implement `Map`
/// is not exhaustive
eernstg marked this conversation as resolved.
Show resolved Hide resolved
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=inline-class

extension type ET1<K, V>(Map<K, V> _) {}

String test(ET1<bool, bool> m) {
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
switch (m) {
case {true: true}:
return "case-1";
case {true: false}:
return "case-2";
case {false: true}:
return "case-3";
case {false: false}:
return "case-4";
case Map():
return "other";
}
}

main() {
test(ET1({false: true}));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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.

/// @assertion Exhaustiveness with map patterns can only be achieved when there
/// is an exhaustive pattern in addition to any map patterns
///
/// @description Check that a switch statement/expression with map patterns and
/// additional exhaustive pattern can be exhaustive.
/// @author sgrekhov22@gmail.com

import "../../../Utils/expect.dart";

String test1_1(Map<bool, bool> m) =>
switch (m) {
{true: true} => "case-1",
{true: false} => "case-2",
{false: true} => "case-3",
{false: false} => "case-4",
Map() => "other"
};

String test1_2(Map<bool, bool> m) =>
switch (m) {
{true: true} => "case-1",
{true: false} => "case-2",
{false: true} => "case-3",
{false: false} => "case-4",
Map() => "other"
};

String test2_1(Map<bool, bool> m) {
switch (m) {
case {true: true}:
return "case-1";
case {true: false}:
return "case-2";
case {false: true}:
return "case-3";
case {false: false}:
return "case-4";
case Map():
return "other";
}
}

String test2_2(Map<bool, bool> m) {
switch (m) {
case {true: true}:
return "case-1";
case {true: false}:
return "case-2";
case {false: true}:
return "case-3";
case {false: false}:
return "case-4";
case Map():
return "other";
}
}

main() {
Expect.equals("other", test1_1(<bool, bool>{}));
Expect.equals("other", test1_2(<bool, bool>{}));
Expect.equals("other", test2_1(<bool, bool>{}));
Expect.equals("other", test2_2(<bool, bool>{}));
Expect.equals("case-1", test1_1({true: true, false: false}));
Expect.equals("case-2", test1_2({true: false, false: false}));
Expect.equals("case-1", test2_1({false: true, true: true}));
Expect.equals("case-1", test2_2({false: false, true: true}));
}
Loading