Skip to content

Compiler generates empty cctor for static fields initialized to null! #42985

@stephentoub

Description

@stephentoub

Version Used:
3.6.0-2.20173.3+2242fa4fb945b97680bdd49eb5dd58285e4abb1c

Steps to Reproduce:

#nullable enable
using System;

public class C0 {
    private static readonly String S1;
}

public class C1 {
    private static readonly String S1 = null!;
}

Expected Behavior:
No cctor should be generated for either type, as in both cases S1 is null.

Actual Behavior:
An empty cctor is generated for C1:

    .method private hidebysig specialname rtspecialname static 
        void .cctor () cil managed 
    {
        // Method begins at RVA 0x2087
        // Code size 1 (0x1)
        .maxstack 8

        IL_0000: ret
    } // end of method C1::.cctor

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions