Skip to content

if case should be negatable #3865

Closed as not planned
Closed as not planned
@feinstein

Description

@feinstein

Sorry if this issue already exists, but I couldn't find anything about this is the search.

I think it would be very useful if we could negate a if-case statement. In my code I wanted to execute something only if a pattern match happened, but I couldn't, so the only other option was using an else with an empty if-case body, which looked very ugly.

What I wanted:

// test case for when a particular go_router route is not the current route:
final matches = router.routerDelegate.currentConfiguration.matches;
if (matches case! [RouteMatchBase(matchedLocation: '/home'), ImperativeRouteMatch(matchedLocation: '/details')]) {
  fail('No route found');
}

What I can do now:

final matches = router.routerDelegate.currentConfiguration.matches;
if (matches case [RouteMatchBase(matchedLocation: '/home'), ImperativeRouteMatch(matchedLocation: '/details')]) {
  // Empty body because I can't negate the if-case
} else {
  fail('No route found');
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProposed language feature that solves one or more problemspatternsIssues related to pattern matching.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions