-
Notifications
You must be signed in to change notification settings - Fork 790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nullness issue - cannot assign null to property #17733
Comments
This might be related to usage of null in unconstrained generic context. Putting that aside, such code can only work if T is constrained to be a reference type. |
@T-Gro here T is a specific reference type, not generic. |
@T-Gro this is what we codegen: [NullableContext(1)]
public class T
{
[Nullable(2)]
internal T v;
[Nullable(2)]
internal T P@;
[Nullable(2)]
public T P
{
[CompilerGenerated]
[DebuggerNonUserCode]
[return: Nullable(2)]
get
{
return P@;
}
[CompilerGenerated]
[DebuggerNonUserCode]
[param: Nullable(2)]
set
{
P@ = value;
}
}
public T()
{
v = null;
P@ = null;
}
public void M()
{
v = null;
P = null;
}
} It seems that we generate context correctly, but do not infer nullness? We infer it for the field, but not for property (is it due to the fact we transorm it to |
Looking at the codegen, I think we even infer it correctly - the attributes are correct, which means C# consumers will see it just fine even. I suspect this might have to do with how and when we process "member val". |
As a workaround, passing in a "fancified null" makes it work: let mutable v : T | null = null
static let nullz : T | null = null
member val P : (T | null) = v with get, set
member this.M() =
v <- null
this.P <- nullz |
In addition,
|
Please provide a succinct description of the issue.
Repro steps
Enable
nullable
.let mutable v
can assignnull
as expected.But
member val P
cannot assignnull
, it causes FS3261.Expected behavior
compile it successfully.
Actual behavior
It causes FS3261 warning.
Known workarounds
Use
Uncheked.defaultof<T | null>
.Related information
Provide any related information (optional):
The text was updated successfully, but these errors were encountered: