Skip to content

Usage of flow analysis attributes should warn outside of annotation context #36588

@RikkiGibson

Description

@RikkiGibson

From LDM notes on 15th May:

The attributes count as “nullable annotations” (with the exception of the Flow attributes that aren’t directly related to nullability) and yield a warning if applied where the annotation context is disabled.

The implementation doesn't appear to do this today.

#nullable disable
using System.Diagnostics.CodeAnalysis;

internal class C<T> where T : class
{
    // 'out T value' should warn, but doesn't
    public bool TryGetValue([MaybeNullWhen(false)] out T value)
    {
        value = default!;
        return false;
    }
}

https://sharplab.io/#v2:EYLgtghgzgLgpgJwD4GIB2BXANliwtwAEAJgJZR4ECwAULQAIAMh9AjAHQAipEA5mgHtYpAMZR2AYQHE4AQTQQsATyjkA3LVoKwcKAAcIIomy49+QmKPFSZ8xSvK0A3rUJvCAbVkwYCUsAx4AFUKXjgACm9ff0C4ABUIBDCYcQAFRIgdeAQAGkJZHAEAdwBZbEs9AkIAXkIAM0UoOABKAF1Xd3oAZkImxThiFgAmQhKIJWA4ADlsLAB1AAs4NCi/APhCEHyfNdiOtxcad2OWHrGJ6dnF5dWY+HDgAQEsQiKltGbCJ0IAX33f2h/Og0UhobIKF70EYSAA8cQAfK8lggiHFNsNnP9uoRHs9CHEEEoAOJwGAANUUGAiHnOkxmOGuaHCDSwTTahAEgXxhAAbpSWv9Did3HysFSaiQ4A1ygBCDRHYUsADs9UacHlxyBPyAA==

Metadata

Metadata

Assignees

No one assigned

    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