Skip to content

#1401. [Patterns] Switch statement tests #1624

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

Merged
merged 7 commits into from
Dec 30, 2022

Conversation

sgrekhov
Copy link
Contributor

No description provided.

Comment on lines +26 to +27
/// @description Checks that constant constructor is not called in case of an
/// object pattern in a switch statement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that in either case, the const constructor and the object pattern, the test will pass. I suggest using a constant expression in the field initializers to make the field values different from the constructor arguments, for example, this.value = value + 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Did the change


String test(Number value) {
switch (value) {
case Number("one", 1):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's supposed to be an object pattern then that line should be reported with a compile-time errors because positional fields aren't allowed in object patterns AFAIK: https://github.com/dart-lang/language/blob/master/accepted/future-releases/0546-patterns/feature-specification.md#object-pattern

It is a compile-time error if:
...

  • A patternField is of the form pattern. Positional fields aren't allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Deleted this test

Copy link
Contributor

@chloestefantsova chloestefantsova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@chloestefantsova chloestefantsova merged commit ac4a905 into dart-lang:master Dec 30, 2022
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Jan 10, 2023
2023-01-07 [email protected] Update test for `CONTINUE_LABEL_INVALID` (dart-lang/co19#1685)
2023-01-06 [email protected] Fixes dart-lang/co19#1653. Typos fixed in some patterns tests (dart-lang/co19#1667)
2023-01-06 [email protected] Fixes dart-lang/co19#1645. Fix typo in constant_A03_t02.dart test (dart-lang/co19#1649)
2023-01-06 [email protected] Fixes dart-lang/co19#1654. Replace || and && by | and & in negative tests (dart-lang/co19#1668)
2023-01-06 [email protected] Fixes dart-lang/co19#1655. Fix using of wrong type in list_A01_t04.dart (dart-lang/co19#1669)
2023-01-06 [email protected] Fixes dart-lang/co19#1656. Fix a typo in list_A02_t01.dart (dart-lang/co19#1670)
2023-01-06 [email protected] Fixes dart-lang/co19#1657. Don't try to test null-check pattern in irrefutable context (dart-lang/co19#1671)
2023-01-06 [email protected] Fixes dart-lang/co19#1658. Fix typos in list_A05_t06.dart (dart-lang/co19#1672)
2023-01-06 [email protected] Fixes dart-lang/co19#1659. Fix typo in logical_or_A02_t01.dart (dart-lang/co19#1673)
2023-01-06 [email protected] Fixes dart-lang/co19#1660. Fix missed compile-time error in logical_or_A04_t03.dart (dart-lang/co19#1674)
2023-01-06 [email protected] Fixes dart-lang/co19#1661. Fix logical_or_A05_t02.dart. Add missed constant (dart-lang/co19#1675)
2023-01-06 [email protected] Fixes dart-lang/co19#1662. Fix errors in map_A01_t04.dart (dart-lang/co19#1676)
2023-01-06 [email protected] Fixes dart-lang/co19#1663. map_A08_t01.dart. Don't use constants in irrefutable context (dart-lang/co19#1677)
2023-01-06 [email protected] Fixes dart-lang/co19#1664. Fix object pattern with parenthesized subpattern (dart-lang/co19#1678)
2023-01-06 [email protected] Fixes dart-lang/co19#1665. object_A06_t01.dart. Add records experimental flag (dart-lang/co19#1679)
2023-01-06 [email protected] Fixes dart-lang/co19#1666. pattern_assignment_A01_t01.dart. Use dynamic instead of Record class (dart-lang/co19#1680)
2023-01-05 [email protected] dart-lang/co19#1401. [Patterns] Switch expression tests (dart-lang/co19#1633)
2023-01-05 [email protected] Fixes dart-lang/co19#1644. Use constant object expression in relational pattern tests (dart-lang/co19#1648)
2023-01-05 [email protected] Fixes dart-lang/co19#1646. Fix typo in constant_A03_t05.dart test (dart-lang/co19#1650)
2023-01-05 [email protected] Fixes dart-lang/co19#1647. Fix typos in variable names in variable_A02_t05.dart test (dart-lang/co19#1651)
2023-01-04 [email protected] Fixes dart-lang/co19#1628. [Patterns] Type argument added to fix map pattern tests (dart-lang/co19#1638)
2023-01-04 [email protected] Fixes dart-lang/co19#1629. [Patterns] Fix logical_and_A03_t02.dart test (dart-lang/co19#1639)
2023-01-04 [email protected] Fixes dart-lang/co19#1634. Fix typo in Records/metadata_annotations_A01_t04.dart (dart-lang/co19#1640)
2023-01-04 [email protected] Fixes dart-lang/co19#1635. Fix typos in object pattern tests (dart-lang/co19#1641)
2023-01-04 [email protected] Fixes dart-lang/co19#1636. Missed `records` experimental flag added to some patterns tests (dart-lang/co19#1642)
2023-01-04 [email protected] Fixes dart-lang/co19#1637. Missed 'const' keywords added to some patterns tests (dart-lang/co19#1643)
2023-01-03 [email protected] Fixes dart-lang/co19#1629. [Patterns] Fix logical_and_A01_t02.dart test (dart-lang/co19#1631)
2023-01-03 [email protected] dart-lang/co19#1627. [Patterns] Typos in constant pattern tests fixed (dart-lang/co19#1630)
2023-01-03 [email protected] Fixes dart-lang/co19#1628. [Patterns] Type argument added to fix list pattern tests (dart-lang/co19#1632)
2022-12-30 [email protected] dart-lang/co19#1401. [Patterns] Switch statement tests (dart-lang/co19#1624)
2022-12-30 [email protected] Fixes dart-lang/co19#1625. Records experimental flag added (dart-lang/co19#1626)
2022-12-28 [email protected] dart-lang/co19#1401. [Patterns] More wildcards tests added (dart-lang/co19#1549)
2022-12-28 [email protected] Fixes dart-lang/co19#1620. Small fixes in patterns tests (dart-lang/co19#1623)
2022-12-28 [email protected] dart-lang/co19#1401. [Patterns] Pattern assignment tests (dart-lang/co19#1617)
2022-12-27 [email protected] Fixes dart-lang/co19#1619. Typos in records tests fixed (dart-lang/co19#1622)
2022-12-27 [email protected] Fixes dart-lang/co19#1618. Map pattern tests fixed, new one added (dart-lang/co19#1621)

Change-Id: I3e8f23d1d842e77481ea2edb2027689a0135afdd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278511
Reviewed-by: Alexander Thomas <[email protected]>
Commit-Queue: Alexander Thomas <[email protected]>
@sgrekhov sgrekhov deleted the co19-1401-switch branch March 22, 2023 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants