-
Notifications
You must be signed in to change notification settings - Fork 143
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
Nullable Reference Types #317
Conversation
Linking dotnet/fsharp#3108 for posterity |
Notes
Test cases
|
Further notes: Small interaction with type abbreviations, e.g. can you do
or
|
ANother note: the syntax
is valid code today because it is interpreted as a union pattern match combined with a type-annotated wildcard pattern: let f2 ((_ : string) | null) = 1 Alternatives that look simpler to implement are
and there is also the option of using
|
This may be an extremely stupid thing to ask but why can't we treat possible nulls from outside things as Option? Null would be represented as None. This way we avoid the possible Option<Nullable>. If we're going to break things (and we're probably not) we might as well break them to be more consistent. Edit: also let me know if this isn't the proper place to discuss this. |
@voronoipotato this is covered in the RFC document |
Specifically here |
Thank you so much guys. |
I'd like to bring nullability for tuples into consideration. An example method from R# SDK I had to deal with recently: [CanBeNull]
Tuple<IProject, TargetFrameworkId> GetProjectAndTargetFrameworkIdByOutputAssembly(FileSystemPath assemblyPath); |
@auduchinok For interop, an analogous situation would be like this: https://sharplab.io/#v2:EYLgZgpghgLgrgJwgZwLQDk4BstWFiAJQkiQDsBjCAFQE8AHFAGhhAEssAfAAQAYACbgEYA3AFgAUH0FCAdIThkYbALYRZAYQD2K+hwgIAygYBubKsnETJAbXRaymHHUbIAFDARwIASgC6ktwAzIIATPwa/ADekvxxgiHUcPQEADzCvEwyvAB8APz8ALJuPtGx8RXcAOz8ZNhYVhUAvpJNQA Which is sort of like this: [NonNullTypes(true)]
public class C
{
[return: Nullable(new bool[] {
true,
false,
false
})]
public Tuple<string, string> M()
{
return null;
}
} And we'd respect the nullability of the construct. I doubt we'd emit that because we don't have |
I adjsuted the syntax to I will pull this and we can continue the discussion |
This is a draft of F# nullable reference types.
It is based primarily on the C# proposal, with additional considerations for F# based on existing behavior we have.
I expect a lot of things that are written down to change over time (i.e., a good lot of what I've written may not actually work out well, but we'll see 😄 )