-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
75 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,15 +12,14 @@ | |
/// space union of E. | ||
/// | ||
/// @description Check a lifted space of a cast pattern in case of not sealed | ||
/// type | ||
/// type. Test switch statement | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=patterns | ||
|
||
int test1(Object obj) { | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
import "../../../Utils/expect.dart"; | ||
|
||
int test(Object obj) { | ||
switch (obj) { | ||
case int(isEven: true) as int: | ||
return 1; | ||
|
@@ -29,15 +28,7 @@ int test1(Object obj) { | |
} | ||
} | ||
|
||
int test2(Object obj) => switch (obj) { | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
int(isEven: true) as int => 1, | ||
int _ => 2 | ||
}; | ||
|
||
main() { | ||
test1(1); | ||
test2(2); | ||
Expect.equals(2 ,test(1)); | ||
Expect.equals(1 ,test(2)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,50 +9,23 @@ | |
/// - The lifted space union of the cast's subpattern in context C. | ||
/// - For each space E in the expanded spaces of M: | ||
/// a. If E is not a subset of C and C is not a subset of M, then the lifted | ||
/// space union of E. | ||
/// space union of E. | ||
/// | ||
/// @description Check a lifted space of a cast pattern in case of a sealed type | ||
/// @description Check a lifted space of a cast pattern in case of not sealed | ||
/// type. Test switch element | ||
/// @author [email protected] | ||
/// @issue 51877 | ||
/// @issue 51986 | ||
// SharedOptions=--enable-experiment=patterns,class-modifiers | ||
// SharedOptions=--enable-experiment=patterns | ||
|
||
import "../../../Utils/expect.dart"; | ||
|
||
sealed class A { | ||
final int field; | ||
A(this.field); | ||
} | ||
class B extends A { | ||
B(int field) : super(field); | ||
} | ||
class C extends A { | ||
C(int field) : super(field); | ||
} | ||
|
||
test1(A a) { | ||
switch (a) { | ||
case C(field: 0) as C: | ||
return 0; | ||
case C _: | ||
return 1; | ||
} | ||
} | ||
|
||
test2(A a) => switch (a) { | ||
C(field: 0) as C => 0, | ||
C _ => 1 | ||
}; | ||
int test(Object obj) => switch (obj) { | ||
int(isEven: true) as int => 1, | ||
int _ => 2 | ||
}; | ||
|
||
main() { | ||
Expect.equals(0, test1(C(0))); | ||
Expect.equals(1, test1(C(1))); | ||
Expect.throws(() { | ||
test1(B(0)); | ||
}); | ||
Expect.equals(0, test2(C(0))); | ||
Expect.equals(1, test2(C(1))); | ||
Expect.throws(() { | ||
test2(B(0)); | ||
}); | ||
Expect.equals(2 ,test(1)); | ||
Expect.equals(1 ,test(2)); | ||
} |
58 changes: 58 additions & 0 deletions
58
LanguageFeatures/Patterns/Exhaustiveness/lifting_cast_pattern_A02_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// 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 The lifted space union for a pattern with matched value type M is | ||
/// ... | ||
/// Cast pattern: | ||
/// The space union spaces for a cast pattern with cast type C is a union of: | ||
/// - The lifted space union of the cast's subpattern in context C. | ||
/// - For each space E in the expanded spaces of M: | ||
/// a. If E is not a subset of C and C is not a subset of M, then the lifted | ||
/// space union of E. | ||
/// | ||
/// @description Check a lifted space of a cast pattern in case of a sealed type | ||
/// @author [email protected] | ||
/// @issue 51877 | ||
// SharedOptions=--enable-experiment=patterns,class-modifiers | ||
|
||
import "../../../Utils/expect.dart"; | ||
|
||
sealed class A { | ||
final int field; | ||
A(this.field); | ||
} | ||
class B extends A { | ||
B(int field) : super(field); | ||
} | ||
class C extends A { | ||
C(int field) : super(field); | ||
} | ||
|
||
test1(A a) { | ||
switch (a) { | ||
case C(field: 0) as C: | ||
return 0; | ||
case C _: | ||
return 1; | ||
} | ||
} | ||
|
||
test2(A a) => switch (a) { | ||
C(field: 0) as C => 0, | ||
C _ => 1 | ||
}; | ||
|
||
main() { | ||
Expect.equals(0, test1(C(0))); | ||
Expect.equals(1, test1(C(1))); | ||
Expect.throws(() { | ||
test1(B(0)); | ||
}); | ||
Expect.equals(0, test2(C(0))); | ||
Expect.equals(1, test2(C(1))); | ||
Expect.throws(() { | ||
test2(B(0)); | ||
}); | ||
} |