Skip to content

Pure null tests should affect both branches #33526

@jcouv

Description

@jcouv

From LDM 2/20/2019 and 3/6/2019 (adjusted {} and derived is Base):

"Pure" tests should set the null-state of x in both branches:

  1. x == null
  2. x != null
  3. (Type)x == null
  4. (Type)x != null
  5. x is null
  6. x?.F
  7. x?[i]
  8. x ?? y
  9. bool [EqualsBehavior]MyEquals(object other)

Note: pure tests 1 through 5 (included) are implemented or verified in #33929

"Not pure" tests should only set the null-state of x in one branch:

  1. x is Y // where Y is not a base of X
  2. x is Y y
  3. x is Y _
  4. x is C { Property = 3 }
  5. TryGetValue([NotNullWhenTrue])
  6. [NotNulllWhenFalse] string.IsNullOrEmpty(s)
  7. derived is Base
  8. x is { }

switch expressions and statements should also use this notion of "pure test" (LDM 3/6/2019).

When closing this issue, we should also close #33526 (and remove references to both issues from code)

Metadata

Metadata

Assignees

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