Replies: 15 comments
-
On those attributes could we have description strings that appear in the warnings? |
Beta Was this translation helpful? Give feedback.
-
@bbarry Taking an example: If you pass a |
Beta Was this translation helpful? Give feedback.
-
I was thinking that it might be useful for The current warning seems pretty sufficient though. Reading further along I love the flow attributes. A |
Beta Was this translation helpful? Give feedback.
-
I'm confused by: public class Array
{
// Result can be default(T) if no match is found
[return: MaybeNull]
public static T Find<T>(T[] array, Predicate<T> match);
} What is the purpose of that attribute? Why not write it as: public class Array
{
public static T? Find<T>(T[] array, Predicate<T> match);
} Is there a difference between using |
Beta Was this translation helpful? Give feedback.
-
@DavidArno This is the whole "unconstrained T" problem. |
Beta Was this translation helpful? Give feedback.
-
Ah, OK. That's worrying then as the use of the attribute looks like an attempt to paper over the cracks rather than fix "the whole "unconstrained T" problem". Hopefully it's just a stop-gap solution therefore. |
Beta Was this translation helpful? Give feedback.
-
I thnk that's an accurate way to describe things. I imagine unconstrained T won't be solved for 8.0. But it's certainly a very obvious and impactful wart that i think the LDM would want to address in the future. |
Beta Was this translation helpful? Give feedback.
-
Will the compiler try to enforce these attributes internally to the method, or only externally to consumers of the API? For example, will this warn: [return: NotNull] object? M() => null; ? |
Beta Was this translation helpful? Give feedback.
-
Per the notes, the priority is to enforce the contract on consumers. But if possible we'd like to enforce the contract on implementers too (this needs more investigation, as it may be tricky in some cases). |
Beta Was this translation helpful? Give feedback.
-
Having used R# for years, the [AllowNull] vs [MayBeNull], and [DisallowNull] vs [NotNull] looks duplicated to me. Is the pre-condition vs post-condition difference really worth separation? The notes also lists two ways to annotate, which achieve the same. This looks like a proof of the redundancy. The only case where the difference is necessary, I can think of, is if the annotation is to be put on properties than accessors. Then the pre-condition vs post-condition can tell whether it applies to getter or setter. |
Beta Was this translation helpful? Give feedback.
-
I am concerned by the points @qrli mentioned as well as a couple of others:
Perhaps we could replace the current 4 attributes with the following 2: public AllowNullAttribute : Attribute
{
public bool In { get; } = true;
public bool Out { get; } = true;
}
public NotNullAttribute : Attribute
{
public bool In { get; } = true;
public bool Out { get; } = true;
} That way we get the common behaviour by default, but it is possible to override it. |
Beta Was this translation helpful? Give feedback.
-
Aside from properties, the difference between pre- and post-condition is also applicable to
I find that interesting. I'll circulate for more thoughts.
I think the redundancy there was different. You could constrain a |
Beta Was this translation helpful? Give feedback.
-
What are the additional generic constraints added for NRT so far? it seems like |
Beta Was this translation helpful? Give feedback.
-
I'm interested if there was any feedback on that? Thanks |
Beta Was this translation helpful? Give feedback.
-
Thanks for the ping. I raised the suggestion with LDM, which ended up leaning towards the current design. The current design allows better alignment between simple attributes and conditional attributes. Also, given the stage in the release cycle there is some bias towards what we have (the bar is higher to motivate a change). |
Beta Was this translation helpful? Give feedback.
-
https://github.com/dotnet/csharplang/blob/master/meetings/2019/LDM-2019-05-15.md
Agenda:
Refining nullability signatures in APIs
Beta Was this translation helpful? Give feedback.
All reactions