Skip to content

Commit

Permalink
#2420. Add relational pattern exhaustiveness tests (#2463)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov authored Jan 4, 2024
1 parent f523471 commit 575cf4f
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2024, 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 Relational pattern doesn't take part in the calculating of the
/// exhaustiveness
///
/// @description Check that relational pattern doesn't take part in the
/// calculating of the exhaustiveness. Test the case when constants in
/// relational patterns are extension types
/// @author sgrekhov22@gmail.com
/// @issue 54506
// SharedOptions=--enable-experiment=inline-class

extension type const BoolET1(bool _) {}
extension type const BoolET2(bool _) implements bool {}

const True1 = BoolET1(true);
const False1 = BoolET1(false);
const True2 = BoolET2(true);
const False2 = BoolET2(false);

String testStatement1(bool b) {
switch (b) {
//^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
case == True1:
return "true";
case == False1:
return "false";
}

}

String testStatement2(bool b) {
switch (b) {
//^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
case == True2:
return "true";
case == False2:
return "false";
}
}

String testExpression1(bool b) => switch (b) {
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
== True1 => "true",
== False1 => "false"
};

String testExpression2(bool b) => switch (b) {
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
== True2 => "true",
== False2 => "false"
};

main() {
testStatement1(true);
testStatement2(false);
testExpression1(true);
testExpression2(false);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) 2024, 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 Relational pattern doesn't take part in the calculating of the
/// exhaustiveness
///
/// @description Check that relational pattern doesn't take part in the
/// calculating of the exhaustiveness. Test the case when expression in
/// a `switch` are extension types
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

extension type const BoolET1(bool _) {}
extension type const BoolET2(bool _) implements bool {}

String testStatement1(BoolET1 b) {
switch (b) {
//^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
case == true:
return "true";
case == false:
return "false";
}

}

String testStatement2(BoolET2 b) {
switch (b) {
//^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
case == true:
return "true";
case == false:
return "false";
}
}

String testExpression1(BoolET1 b) => switch (b) {
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
== true => "true",
== false => "false"
};

String testExpression2(BoolET2 b) => switch (b) {
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
== true => "true",
== false => "false"
};

main() {
testStatement1(BoolET1(true));
testStatement2(BoolET2(false));
testExpression1(BoolET1(false));
testExpression2(BoolET2(true));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2024, 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 Relational pattern doesn't take part in the calculating of the
/// exhaustiveness
///
/// @description Check that relational pattern doesn't take part in the
/// calculating of the exhaustiveness. Test the case when both expression in
/// a `switch` and constants in relational patterns are extension types
/// @author sgrekhov22@gmail.com
/// @issue 54506
// SharedOptions=--enable-experiment=inline-class

extension type const BoolET1(bool _) {}
extension type const BoolET2(bool _) implements bool {}

const True1 = BoolET1(true);
const False1 = BoolET1(false);
const True2 = BoolET2(true);
const False2 = BoolET2(false);

String testStatement1(BoolET1 b) {
switch (b) {
//^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
case == True1:
return "true";
case == False1:
return "false";
}

}

String testStatement2(BoolET2 b) {
switch (b) {
//^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
case == True2:
return "true";
case == False2:
return "false";
}
}

String testExpression1(BoolET1 b) => switch (b) {
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
== True1 => "true",
== False1 => "false"
};

String testExpression2(BoolET2 b) => switch (b) {
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
== True2 => "true",
== False2 => "false"
};

main() {
testStatement1(True1);
testStatement2(False2);
testExpression1(False1);
testExpression2(True2);
}

0 comments on commit 575cf4f

Please sign in to comment.