Skip to content

'Use pattern matching' doesn't recognize 'is object' as a non-null check #36315

@sharwell

Description

@sharwell

Version Used: 16.2 Preview 1

Steps to Reproduce:

int Method(object obj) {
  var str = obj as string;
  if (str is object) {
    return 1;
  }

  return 0;
}

Expected Behavior:

A code fix is offered to use pattern matching:

int Method(object obj) {
  if (obj is string str) {
    return 1;
  }

  return 0;
}

Actual Behavior:

No code fix is offered.

Metadata

Metadata

Assignees

Labels

Area-IDEBugIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringsResolution-FixedThe bug has been fixed and/or the requested behavior has been implemented

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions