Skip to content

Nullable reference types bias towards use of 'var' #23281

@sharwell

Description

@sharwell

Version Used: Preview 11152017

I have observed several cases where changing the return type of a member results in cascading updates through the code. In many cases, local variables declared to hold the result of invoking these members were already properly used, and the only reason why an update was required is the local variable was declared using the type name rather than using var.

It would be very helpful for the migration process if the semantics/warnings were slightly altered:

  • When a nullable value is assigned to a non-nullable local variable in the initializer for the local variable, use a dedicated warning number for the situation and treat the variable as having been declared with a nullable type.
  • Provide a code fix for this warning number which adds the missing ?.

This warning can be disabled during the initial migration process for a project that prefers to not use var, with a final pass at the end to enable the warning and apply the code fix to clean up the code base.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions