Replies: 3 comments
-
I believe this is by design. It was not intended that |
Beta Was this translation helpful? Give feedback.
0 replies
-
This gives an unexpected warning as well #nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
public class C {
string? Getter() {
return null;
}
void Setter(string s) {
}
[MaybeNull]
public string Property {
get => Getter(); // get unexpected warning here
set => Setter(value);
}
public void Test() {
Property = ""; // no warning here as expected
Property = null; // get warning here as expected
Setter(Property); // get warning here as expected
}
} So it doesn't seem possible to have a property with different nullability for the getter and setter when the getter and setter are expression bodied. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Moving to csharplang because this is by-design for the compiler |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Version Used: master (23 September 2019) via https://sharplab.io
Steps to Reproduce:
Expected Behavior: Given a property with the
DisallowNull
attribute it should mean that the return value can be null butvalue
parameter of the setter cannot be null.Actual Behavior: The code analysis gets this right when assigning to a property, but not in the property declaration.
Beta Was this translation helpful? Give feedback.
All reactions