Skip to content

Warn when the type on the right of is is nullable but the type on the left is notΒ #61180

@DanTup

Description

@DanTup

Edit: This issue has changed a little from what was originally reported, and the consensus is that the example code should warn that the ? in is String? should be removed since c is not nullable. With that removed, the static type is as expected.

--

In the following code, the variable c is considered Object even though it seems like the when clause should ensure that is is String?:

void f(Object c) {
  switch (true) {
    case true when c is String?:
      // A value of type 'Object' can't be assigned to a variable of type 'String'.
      String a = c;
  }
}

I would expect it to be String? here (or maybe even String since it was never nullable in the first place). I'm not sure if this is a bug, a missing feature, or behaves like this for a reason I'm overlooking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-warningIssues with the analyzer's Warning codestype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions