Skip to content

Commit

Permalink
Fix dart-lang#2535. Add patterns constants tests for extension types
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Feb 12, 2024
1 parent 2ec352f commit 4b80690
Show file tree
Hide file tree
Showing 24 changed files with 538 additions and 55 deletions.
61 changes: 61 additions & 0 deletions LanguageFeatures/Patterns/constant_A06_t10.dart
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:
}
}
58 changes: 58 additions & 0 deletions LanguageFeatures/Patterns/constant_A06_t11.dart
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
}
66 changes: 66 additions & 0 deletions LanguageFeatures/Patterns/constant_A06_t12.dart
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();
}
8 changes: 5 additions & 3 deletions LanguageFeatures/Patterns/relational_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
// BSD-style license that can be found in the LICENSE file.

/// @assertion relationalPattern ::=
/// ( equalityOperator | relationalOperator) relationalExpression
/// ( equalityOperator | relationalOperator) bitwiseOrExpression
///
/// A relational pattern lets you compare the matched value to a given constant
/// using any of the equality or relational operators: ==, !=, <, >, <=, and >=.
/// The pattern matches when calling the appropriate operator on the matched
/// value with the constant as an argument returns true. It is a compile-time
/// error if relationalExpression is not a valid constant expression.
/// value with the constant as an argument returns true.
///
/// It is a compile-time error if bitwiseOrExpression is not a valid constant
/// expression.
///
/// @description Checks a relational pattern in a switch expression
/// @author sgrekhov22@gmail.com
Expand Down
8 changes: 5 additions & 3 deletions LanguageFeatures/Patterns/relational_A01_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
// BSD-style license that can be found in the LICENSE file.

/// @assertion relationalPattern ::=
/// ( equalityOperator | relationalOperator) relationalExpression
/// ( equalityOperator | relationalOperator) bitwiseOrExpression
///
/// A relational pattern lets you compare the matched value to a given constant
/// using any of the equality or relational operators: ==, !=, <, >, <=, and >=.
/// The pattern matches when calling the appropriate operator on the matched
/// value with the constant as an argument returns true. It is a compile-time
/// error if relationalExpression is not a valid constant expression.
/// value with the constant as an argument returns true.
///
/// It is a compile-time error if bitwiseOrExpression is not a valid constant
/// expression.
///
/// @description Checks a relational subpattern in a switch expression
/// @author sgrekhov22@gmail.com
Expand Down
8 changes: 5 additions & 3 deletions LanguageFeatures/Patterns/relational_A02_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
// BSD-style license that can be found in the LICENSE file.

/// @assertion relationalPattern ::=
/// ( equalityOperator | relationalOperator) relationalExpression
/// ( equalityOperator | relationalOperator) bitwiseOrExpression
///
/// A relational pattern lets you compare the matched value to a given constant
/// using any of the equality or relational operators: ==, !=, <, >, <=, and >=.
/// The pattern matches when calling the appropriate operator on the matched
/// value with the constant as an argument returns true. It is a compile-time
/// error if relationalExpression is not a valid constant expression.
/// value with the constant as an argument returns true.
///
/// It is a compile-time error if bitwiseOrExpression is not a valid constant
/// expression.
///
/// @description Checks a relational pattern in a switch statement
/// @author sgrekhov22@gmail.com
Expand Down
8 changes: 5 additions & 3 deletions LanguageFeatures/Patterns/relational_A02_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
// BSD-style license that can be found in the LICENSE file.

/// @assertion relationalPattern ::=
/// ( equalityOperator | relationalOperator) relationalExpression
/// ( equalityOperator | relationalOperator) bitwiseOrExpression
///
/// A relational pattern lets you compare the matched value to a given constant
/// using any of the equality or relational operators: ==, !=, <, >, <=, and >=.
/// The pattern matches when calling the appropriate operator on the matched
/// value with the constant as an argument returns true. It is a compile-time
/// error if relationalExpression is not a valid constant expression.
/// value with the constant as an argument returns true.
///
/// It is a compile-time error if bitwiseOrExpression is not a valid constant
/// expression.
///
/// @description Checks a relational subpattern in a switch statement
/// @author sgrekhov22@gmail.com
Expand Down
8 changes: 5 additions & 3 deletions LanguageFeatures/Patterns/relational_A03_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
// BSD-style license that can be found in the LICENSE file.

/// @assertion relationalPattern ::=
/// ( equalityOperator | relationalOperator) relationalExpression
/// ( equalityOperator | relationalOperator) bitwiseOrExpression
///
/// A relational pattern lets you compare the matched value to a given constant
/// using any of the equality or relational operators: ==, !=, <, >, <=, and >=.
/// The pattern matches when calling the appropriate operator on the matched
/// value with the constant as an argument returns true. It is a compile-time
/// error if relationalExpression is not a valid constant expression.
/// value with the constant as an argument returns true.
///
/// It is a compile-time error if bitwiseOrExpression is not a valid constant
/// expression.
///
/// @description Checks a relational pattern in an if-case statement
/// @author sgrekhov22@gmail.com
Expand Down
8 changes: 5 additions & 3 deletions LanguageFeatures/Patterns/relational_A03_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
// BSD-style license that can be found in the LICENSE file.

/// @assertion relationalPattern ::=
/// ( equalityOperator | relationalOperator) relationalExpression
/// ( equalityOperator | relationalOperator) bitwiseOrExpression
///
/// A relational pattern lets you compare the matched value to a given constant
/// using any of the equality or relational operators: ==, !=, <, >, <=, and >=.
/// The pattern matches when calling the appropriate operator on the matched
/// value with the constant as an argument returns true. It is a compile-time
/// error if relationalExpression is not a valid constant expression.
/// value with the constant as an argument returns true.
///
/// It is a compile-time error if bitwiseOrExpression is not a valid constant
/// expression.
///
/// @description Checks a relational subpattern in an if-else statement
/// @author sgrekhov22@gmail.com
Expand Down
10 changes: 6 additions & 4 deletions LanguageFeatures/Patterns/relational_A04_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
// BSD-style license that can be found in the LICENSE file.

/// @assertion relationalPattern ::=
/// ( equalityOperator | relationalOperator) relationalExpression
/// ( equalityOperator | relationalOperator) bitwiseOrExpression
///
/// A relational pattern lets you compare the matched value to a given constant
/// using any of the equality or relational operators: ==, !=, <, >, <=, and >=.
/// The pattern matches when calling the appropriate operator on the matched
/// value with the constant as an argument returns true. It is a compile-time
/// error if relationalExpression is not a valid constant expression.
/// value with the constant as an argument returns true.
///
/// @description Check that it is a compile-time error if relationalExpression
/// It is a compile-time error if bitwiseOrExpression is not a valid constant
/// expression.
///
/// @description Check that it is a compile-time error if `bitwiseOrExpression`
/// is not a valid constant expression. Test switch statement
/// @author sgrekhov22@gmail.com
Expand Down
10 changes: 6 additions & 4 deletions LanguageFeatures/Patterns/relational_A04_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
// BSD-style license that can be found in the LICENSE file.

/// @assertion relationalPattern ::=
/// ( equalityOperator | relationalOperator) relationalExpression
/// ( equalityOperator | relationalOperator) bitwiseOrExpression
///
/// A relational pattern lets you compare the matched value to a given constant
/// using any of the equality or relational operators: ==, !=, <, >, <=, and >=.
/// The pattern matches when calling the appropriate operator on the matched
/// value with the constant as an argument returns true. It is a compile-time
/// error if relationalExpression is not a valid constant expression.
/// value with the constant as an argument returns true.
///
/// @description Check that it is a compile-time error if relationalExpression
/// It is a compile-time error if bitwiseOrExpression is not a valid constant
/// expression.
///
/// @description Check that it is a compile-time error if `bitwiseOrExpression`
/// is not a valid constant expression. Test switch expression
/// @author sgrekhov22@gmail.com
Expand Down
10 changes: 6 additions & 4 deletions LanguageFeatures/Patterns/relational_A04_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
// BSD-style license that can be found in the LICENSE file.

/// @assertion relationalPattern ::=
/// ( equalityOperator | relationalOperator) relationalExpression
/// ( equalityOperator | relationalOperator) bitwiseOrExpression
///
/// A relational pattern lets you compare the matched value to a given constant
/// using any of the equality or relational operators: ==, !=, <, >, <=, and >=.
/// The pattern matches when calling the appropriate operator on the matched
/// value with the constant as an argument returns true. It is a compile-time
/// error if relationalExpression is not a valid constant expression.
/// value with the constant as an argument returns true.
///
/// @description Check that it is a compile-time error if relationalExpression
/// It is a compile-time error if bitwiseOrExpression is not a valid constant
/// expression.
///
/// @description Check that it is a compile-time error if `bitwiseOrExpression`
/// is not a valid constant expression. Test an if-case statement
/// @author sgrekhov22@gmail.com
Expand Down
10 changes: 6 additions & 4 deletions LanguageFeatures/Patterns/relational_A04_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
// BSD-style license that can be found in the LICENSE file.

/// @assertion relationalPattern ::=
/// ( equalityOperator | relationalOperator) relationalExpression
/// ( equalityOperator | relationalOperator) bitwiseOrExpression
///
/// A relational pattern lets you compare the matched value to a given constant
/// using any of the equality or relational operators: ==, !=, <, >, <=, and >=.
/// The pattern matches when calling the appropriate operator on the matched
/// value with the constant as an argument returns true. It is a compile-time
/// error if relationalExpression is not a valid constant expression.
/// value with the constant as an argument returns true.
///
/// @description Check that it is a compile-time error if relationalExpression
/// It is a compile-time error if bitwiseOrExpression is not a valid constant
/// expression.
///
/// @description Check that it is a compile-time error if `bitwiseOrExpression`
/// is not a valid constant expression. Test subexpression
/// @author sgrekhov22@gmail.com
Expand Down
Loading

0 comments on commit 4b80690

Please sign in to comment.