dotnet/roslyn

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

オープン

#43,587 opened on 2020/04/23

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)C# (4,257 件のフォーク)batch import
Area-CompilersBugFeature - Nullable Reference Typeshelp wanted

Repository metrics

Stars
 (20,414 個のスター)
PR merge metrics
 (平均マージ 6d 17h) (30d で 256 merged PRs)

説明

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

コントリビューターガイド