forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dart-lang#2535. Add patterns constants tests for extension types
- Loading branch information
Showing
24 changed files
with
538 additions
and
55 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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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 constantPattern ::= booleanLiteral | ||
/// | nullLiteral | ||
/// | '-'? numericLiteral | ||
/// | stringLiteral | ||
/// | symbolLiteral | ||
/// | identifier | ||
/// | qualifiedName | ||
/// | constObjectExpression | ||
/// | 'const' typeArguments? '[' elements? ']' | ||
/// | 'const' typeArguments? '{' elements? '}' | ||
/// | 'const' '(' expression ')' | ||
/// | ||
/// A constant pattern determines if the matched value is equal to the | ||
/// constant's value. We don't allow all expressions here because many | ||
/// expression forms syntactically overlap other kinds of patterns. We avoid | ||
/// ambiguity while supporting terse forms of the most common constant | ||
/// expressions like so: | ||
/// ... | ||
/// It is a compile-time error if a constant pattern's value is not a valid | ||
/// constant expression. | ||
/// | ||
/// @description Check that it is a compile-time error if a constant pattern's | ||
/// value is not a valid constant expression. Test switch statement | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
extension type NumET(num n) implements num {} | ||
extension type const IntET(int i) implements int {} | ||
|
||
main() { | ||
Object value = Object(); | ||
final v = IntET(0); | ||
|
||
switch (value) { | ||
case v: | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
break; | ||
case IntET(0): | ||
// ^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
break; | ||
case v.i: | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
break; | ||
case const NumET(1): | ||
// ^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
default: | ||
} | ||
} |
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) 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 constantPattern ::= booleanLiteral | ||
/// | nullLiteral | ||
/// | '-'? numericLiteral | ||
/// | stringLiteral | ||
/// | symbolLiteral | ||
/// | identifier | ||
/// | qualifiedName | ||
/// | constObjectExpression | ||
/// | 'const' typeArguments? '[' elements? ']' | ||
/// | 'const' typeArguments? '{' elements? '}' | ||
/// | 'const' '(' expression ')' | ||
/// | ||
/// A constant pattern determines if the matched value is equal to the | ||
/// constant's value. We don't allow all expressions here because many | ||
/// expression forms syntactically overlap other kinds of patterns. We avoid | ||
/// ambiguity while supporting terse forms of the most common constant | ||
/// expressions like so: | ||
/// ... | ||
/// It is a compile-time error if a constant pattern's value is not a valid | ||
/// constant expression. | ||
/// | ||
/// @description Check that it is a compile-time error if a constant pattern's | ||
/// value is not a valid constant expression. Test if-case statement | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
extension type NumET(num n) implements num {} | ||
extension type const IntET(int i) implements int {} | ||
|
||
main() { | ||
Object value = Object(); | ||
final v = IntET(0); | ||
|
||
if (value case v) {} | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
if (value case IntET(0)) {} | ||
// ^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
if (value case v.i) {} | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
if (value case const NumET(1)) {} | ||
// ^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
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,66 @@ | ||
// 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 constantPattern ::= booleanLiteral | ||
/// | nullLiteral | ||
/// | '-'? numericLiteral | ||
/// | stringLiteral | ||
/// | symbolLiteral | ||
/// | identifier | ||
/// | qualifiedName | ||
/// | constObjectExpression | ||
/// | 'const' typeArguments? '[' elements? ']' | ||
/// | 'const' typeArguments? '{' elements? '}' | ||
/// | 'const' '(' expression ')' | ||
/// | ||
/// A constant pattern determines if the matched value is equal to the | ||
/// constant's value. We don't allow all expressions here because many | ||
/// expression forms syntactically overlap other kinds of patterns. We avoid | ||
/// ambiguity while supporting terse forms of the most common constant | ||
/// expressions like so: | ||
/// ... | ||
/// It is a compile-time error if a constant pattern's value is not a valid | ||
/// constant expression. | ||
/// | ||
/// @description Check that it is a compile-time error if a constant pattern's | ||
/// value is not a valid constant expression. Test switch expression | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
extension type NumET(num n) implements num {} | ||
extension type const IntET(int i) implements int {} | ||
|
||
int test() { | ||
Object value = Object(); | ||
final v = IntET(0); | ||
|
||
return switch (value) { | ||
v => 1, | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
IntET(1) => 2, | ||
// ^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
v.i => 3, | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const NumET(4) => 4, | ||
// ^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const (NumET(5).n) => 5, | ||
// ^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
_ => -1 | ||
}; | ||
} | ||
|
||
main() { | ||
test(); | ||
} |
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.