Skip to content

Pattern matching: Allow nullable variables to be defined only in specific cases #4632

@rrousselGit

Description

@rrousselGit

Consider:

switch (obj) {
  case Foo():
  case Bar(:final int? property):
}

At the moment, it is not possible to do print(property) within said case, because not all cases define the property variable.
But int? is nullable. Could we instead consider that it is defined but null?

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProposed language feature that solves one or more problems

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions