Skip to content

Roslyn fails to verify nullable attributes on lambda expressions in delegate conversions #55649

@TessenR

Description

@TessenR

Version Used:

Branch main (14 Aug 2021)
Latest commit 0954614 by David Barbet:
Merge pull request #55599 from dibarbet/shutdown_jsonrpc_disconnect

Shutdown LSP server on streamjsonrpc disconnect

Steps to Reproduce:

Compile and run the following code

#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;

Func<string?, string> d = ([DisallowNull] string? x) => x;
d(null).ToString();

Expected Behavior:
Warning for the assignment of d since the assigned function doesn't accept null values which are legal as inputs of the delegate

Actual Behavior:
No warnings at all in the program above. The program crashes at runtime with a NullReferenceException

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions