dotnet/roslyn

[MemberNotNull] is not processed for write acceses to ref returning properties

开放

#43,587 创建于 2020年4月23日

 (0 条评论) (0 个反应) (0 位负责人)C# (4,257 个派生)batch import
Area-CompilersBugFeature - Nullable Reference Typeshelp wanted

仓库指标

星标
 (20,414 个星标)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 256 个 PR)

描述

Version Used:

commit a1b867054dff97e5e5f44c7ad742c8ffb740b2eb
Merge: 8f4fdad99ae 6bf71e1a37d
Author: msftbot[bot] <48340428+msftbot[bot]@users.noreply.github.com>
Date:   Wed Apr 22 09:50:57 2020 +0000

    Merge pull request #43554 from CyrusNajmabadi/renameOOP4

    Move the 'finding' portoin of rename out of process.

Steps to Reproduce:

Compile the following code

using System.Diagnostics.CodeAnalysis;

class C
{
  public string? Prop1 { get; set; }
  public string? Prop2 { get; set; }

  private int field;

  [MemberNotNull(nameof(Prop1))]
  private ref int Init
  {
    [MemberNotNull(nameof(Prop2))]
    get
    {
      Prop1 = Prop2 = "";
      return ref field;
    }
  }                                    

  void M1()
  {
    Init = 1;
    Prop1.ToString(); // warning
    Prop2.ToString(); // warning
  }

  void M2()
  {
    _ = Init;
    Prop1.ToString();
    Prop2.ToString();
  }
}

Expected Behavior: No warnings. Both methods contain calls to ``get_Init()that is guaranteed to initialize bothProp1andProp2` to non-nullable values before the methods access them

Actual Behavior: CS8602: Dereference of a possibly null reference. warnings reported for Prop1 and Prop2 in M1 but not M2

贡献者指南