Skip to content

System.Runtime.CompilerServices.NullableAttribute is not being applied #312

Open
@adrianoc

Description

for instance, the IL for

class Foo<T>
{
}

is missing the attribute. Below is the IL generated by the compiler for the same code:

.class private auto ansi beforefieldinit Foo`1<T>
    extends [System.Runtime]System.Object
{
    // Missing attribute
    .param type T
        .custom instance void [System.Runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = (
            01 00 02 00 00
        )
   // ...

} // end of class Foo`1

There are many more scenarios that need to be handled as well.

References

Notes

  1. This task also includes emitting NullableContextAttribute.
  2. For generic type parameters the argument to the attribute constructor is defined by the presence/absence of notnull constraint
  3. One of the following values should be provided for each type parameter:
    1. 0 meaning the type parameter is oblivious in regards to nullability (not sure how to construct a test scenario for this)
    2. 1 if the type parameter is non nullable (i.e, has the notnull constraint)
    3. 2 if the type parameter is nullable
  4. For generic types the NullableAttribute constructor is passed an array of the values above, one for each type parameter.
  5. NullableContextAttribute / NullableAttribute are applied in a way to minimize the number of attributes required, so in general, NullableContextAttribute is applied with whichever value is more common in the method and NullableAttribute is applied for elements that differs.
  6. #nullable pre-processor directive set to enable is equivalent do no preprocessor

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions