Skip to content

Missing nullability warnings for invalid constant values #50580

@TessenR

Description

@TessenR

Version Used:

Branch master (14 Jan 2021)
Latest commit f3d7c35 by Julien Couvreur:
Don't check initializer on static record ctor (#50176)

Steps to Reproduce:

Compile and run the following code

#nullable enable
string s = C.MyConst;
s.ToString();

class C
{
  public const string MyConst = null;
}

Expected Behavior:
Warning for public const string MyConst = null;

Actual Behavior:
No warnings. The program crashes at runtime with a NullReferenceExceptions

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions