Skip to content

Roslyn doesn't check nullability violations in delegate conversions caused by flow annotations #44129

@TessenR

Description

@TessenR

Version Used:

commit 27654b066e600a350706a13ebd67d1da542c1a7b
Merge: 436d17816f6 0c9f90368a5
Author: msftbot[bot] <48340428+msftbot[bot]@users.noreply.github.com>
Date:   Thu May 7 05:33:48 2020 +0000

    Merge pull request #44029 from dotnet/merges/release/dev16.7-preview1-to-master

    Merge release/dev16.7-preview1 to master

Steps to Reproduce:

Compile and run the following code

using System;
using System.Collections.Generic;
using System.Linq;

#nullable enable
public class D
{
  public static void Main()
  {
    IEnumerable<string> e = new string[0];
    Func<string> f = e.FirstOrDefault;
    f().ToString();
  }
}

Expected Behavior:
Warning for conversion Func<string> f = e.FirstOrDefault because FirstOrDefault uses [return: MaybeNull] annotation

Actual Behavior:
No warnings. The code crashes at runtime with a NullReferenceException

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