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 #1644. Use constant object expression in relational pattern tests #1648

Merged
merged 1 commit into from
Jan 5, 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
12 changes: 6 additions & 6 deletions LanguageFeatures/Patterns/relational_A06_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ class C {

String test1(C c) {
return switch (c) {
< C(0) => "negative",
>= C(0) => "positive",
< const C(0) => "negative",
>= const C(0) => "positive",
_ => "Impossible!"
};
}

String test2(C c) {
return switch (c) {
>= C(0) => "positive",
< C(0) => "negative",
>= const C(0) => "positive",
< const C(0) => "negative",
_ => "Impossible!"
};
}

String test3(C c) {
return switch (c) {
== C(0) => "zero",
!= C(0) => "non-zero",
== const C(0) => "zero",
!= const C(0) => "non-zero",
_ => "Impossible!"
};
}
Expand Down
8 changes: 4 additions & 4 deletions LanguageFeatures/Patterns/relational_A06_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class C {
}

String test(List<C> list) => switch (list) {
[> C(0) && <= C(2)] => "case 1",
[== C(42)] => "case 2",
[>= C(10) && < C(20)] => "case 3",
[!= C(100)] => "case 4",
[> const C(0) && <= const C(2)] => "case 1",
[== const C(42)] => "case 2",
[>= const C(10) && < const C(20)] => "case 3",
[!= const C(100)] => "case 4",
_ => "default"
};

Expand Down
10 changes: 5 additions & 5 deletions LanguageFeatures/Patterns/relational_A06_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class C {

void test1(C c, String expected) {
switch (c) {
case < C(0):
case < const C(0):
Expect.equals("negative", expected);
break;
case == C(0):
case == const C(0):
Expect.equals("zero", expected);
break;
case > C(0):
case > const C(0):
Expect.equals("positive", expected);
break;
default:
Expand All @@ -49,10 +49,10 @@ void test1(C c, String expected) {

void test2(C c, String expected) {
switch (c) {
case != C(0):
case != const C(0):
Expect.equals("non-zero", expected);
break;
case == C(0):
case == const C(0):
Expect.equals("zero", expected);
break;
default:
Expand Down
8 changes: 4 additions & 4 deletions LanguageFeatures/Patterns/relational_A06_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ class C {

void test(List<C> list, String expected) {
switch (list) {
case [> C(0) && <= C(2)]:
case [> const C(0) && <= const C(2)]:
Expect.equals("case 1", expected);
break;
case [== C(42)]:
case [== const C(42)]:
Expect.equals("case 2", expected);
break;
case [>= C(10) && < C(20)]:
case [>= const C(10) && < const C(20)]:
Expect.equals("case 3", expected);
break;
case [!= C(100)]:
case [!= const C(100)]:
Expect.equals("case 4", expected);
break;
default:
Expand Down
10 changes: 5 additions & 5 deletions LanguageFeatures/Patterns/relational_A06_t05.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ class C {
}

void test1(C c, String expected) {
if (c case < C(0)) {
if (c case < const C(0)) {
Expect.equals("negative", expected);
} else if (c case == C(0)) {
} else if (c case == const C(0)) {
Expect.equals("zero", expected);
} else if (c case > C(0)) {
} else if (c case > const C(0)) {
Expect.equals("positive", expected);
} else {
Expect.fail("One of the cases above should match");
}
}

void test2(C c, String expected) {
if (c case != C(0)) {
if (c case != const C(0)) {
Expect.equals("non-zero", expected);
} else if (c case == C(0)) {
} else if (c case == const C(0)) {
Expect.equals("zero", expected);
} else {
Expect.fail("One of the cases above should match");
Expand Down
8 changes: 4 additions & 4 deletions LanguageFeatures/Patterns/relational_A06_t06.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class C {
}

void test(List<C> list, String expected) {
if (list case [> C(0) && <= C(2)]) {
if (list case [> const C(0) && <= const C(2)]) {
Expect.equals("case 1", expected);
} else if (list case [== C(42)]) {
} else if (list case [== const C(42)]) {
Expect.equals("case 2", expected);
} else if (list case [>= C(10) && < C(20)]) {
} else if (list case [>= const C(10) && < const C(20)]) {
Expect.equals("case 3", expected);
} else if (list case [!= C(100)]) {
} else if (list case [!= const C(100)]) {
Expect.equals("case 4", expected);
} else {
Expect.equals("default", expected);
Expand Down