NRT - Provide switch to catch non-nullable refs from null-oblivious assemblies #2807
Replies: 3 comments
-
Right now our project using Resharper in pessimistic mode, so we have an ability to treat all 3rd library code as something that can produce null and we need either to annotate it with external annotations or write null checks after each method. But Resharper is very limited in nullable annotating and in flow-analysis, because it lacks nullability when passing delegates, using more of linq etc., also I'm only able to mark |
Beta Was this translation helpful? Give feedback.
-
Exactly -- the whole point of NRT was to provide native support for compile-time null-safety. As it stands, it's just not enough, given the massive base of null-oblivious code out there. |
Beta Was this translation helpful? Give feedback.
-
I suppose that you mean any IDE generated content. This should not be an issue if, for null-oblivious assemblies, either one of the followings is shown
For out-dated documents on the Internet, users should be aware of null-obliviousness if they see any compiler warnings. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I propose the addition of a
#nullable strict
notation, or a compiler switch, or something similar, that tells the compiler to catch non-null-safe references to types declared or implemented in legacy null-oblivious assemblies. Perhaps a new, distinct compiler warning/error could be created to support this case: "Possible null reference to null-oblivious type".From the discussion in #2205, there's a significant hole in the Nullable Reference Types implementation that allows references to objects of types implemented in null-oblivious assemblies to skate past compile-time nullability checks by not requiring the
?
on such references.One argument given is that there would be a mismatch between the null-oblivious notation
T
and the nullable-notatedT?
that might confuse newcomers to the language. I get that. I really do. That's why I'm recommending an opt-in strategy here, that allows those developers that want the extra safety to avail themselves as needed.Beta Was this translation helpful? Give feedback.
All reactions