-
-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Labels
🐛 bugSomething isn't workingSomething isn't working
Milestone
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
- https://github.com/dotnet/roslyn/blob/main/docs/features/nullable-metadata.md
- https://codeblog.jonskeet.uk/2019/02/10/nullableattribute-and-c-8/
- System.Runtime.CompilerServices.NullableAttribute is not returning if there are no even properties with null and without null. dotnet/roslyn#39133
- https://dev.to/maartenba/internals-of-c-nullable-reference-types-migrating-to-nullable-reference-types-part-2-gmd
Notes
- This task also includes emitting
NullableContextAttribute. - For generic type parameters the argument to the attribute constructor is defined by the presence/absence of
notnullconstraint - One of the following values should be provided for
eachtype parameter:- 0 meaning the
type parameteris oblivious in regards to nullability (not sure how to construct a test scenario for this) - 1 if the type parameter is non nullable (i.e, has the
notnullconstraint) - 2 if the type parameter is nullable
- 0 meaning the
- For generic types the
NullableAttributeconstructor is passed an array of the values above, one for eachtype parameter. NullableContextAttribute/NullableAttributeare applied in a way to minimize the number of attributes required, so in general,NullableContextAttributeis applied with whichever value is more common in the method andNullableAttributeis applied for elements that differs.#nullablepre-processor directive set toenableis equivalent do no preprocessor
Metadata
Metadata
Assignees
Labels
🐛 bugSomething isn't workingSomething isn't working