Repository navigation
Open
Labels
Milestone
Description
Issue description
A specific scenario is broken by enabling nullness checking, manifesting as FS0001.
Choose one or more from the following categories of impact
- Unexpected nullness warning (false positive in nullness checking, code uses --checknulls and langversion:preview).
- Missing nullness warning in a case which can produce nulls (false negative, code uses --checknulls and langversion:preview).
- Breaking change related to older
nullconstructs in code not using the checknulls switch. - Breaking change related to generic code and explicit type constraints (
null,not null). - Type inference issue (i.e. code worked without type annotations before, and applying the --checknulls enforces type annotations).
- C#/F# interop issue related to nullness metadata.
- Other (none of the categories above apply).
Operating System
Windows (Default)
What .NET runtime/SDK kind are you seeing the issue on
.NET SDK (.NET Core, .NET 5+)
.NET Runtime/SDK version
.NET 9
Reproducible code snippet and actual behavior
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharpPlus" Version="1.6.1" />
</ItemGroup>
</Project>open FSharpPlus
let parseInt () : Result<int, string> =
Ok 42
type SomeRecordWrapper = {
Value: int
}
let repro () =
let result =
monad {
let! parsed = parseInt ()
return {
Value = parsed
}
}
match result with
| Ok _ ->
()
| Error _ ->
()With Nullable enabled, this results in:
0>Program.fs(20,7): Error FS0001 : '.Delay' does not support the type 'Result<SomeRecordWrapper,'a>', because the latter lacks the required (real or built-in) member 'Delay'
0>Program.fs(19,11): Warning FS0025 : Incomplete pattern matches on this expression.
With Nullable disabled, the code compiles fine.
Possible workarounds
None that I know of.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNew
Activity
T-Gro commentedon Nov 20, 2024
I am confused about the source line of the error, like 20 is the " | Ok " match clause, isn't it?
johnnyggalt commentedon Nov 20, 2024
@T-Gro that's correct. It seems to me that the combination of null checking and the specifics of my scenario is causing the compiler to get confused.
T-Gro commentedon Nov 20, 2024
Some previous defaults of type inference, such as falling back to 'obj' in some cases, are no longer possible with nullness due to the difference between obj and objnull.
This should be validate with trying similar code with and without explicit annotations for the usages of the Result.
Looking at the code, it should be able to derive type of Result to be <int,string> (non nullable string) .
johnnyggalt commentedon Nov 23, 2024
@T-Gro if I explicitly type the
result, it does compile:Whilst this should get me past my issue, it feels off to me. At the very least, the compiler error message is hella confusing. But on top of that, if I don't explicitly type
resultit still correctly inferred, so the explicit typing feels unnecessary from that perspective:T-Gro commentedon Nov 25, 2024
It does indeed.
It has to do with the constraints implied by the use of "monad" CE - not that it has an issue in it, but rather the compiler solving constraints wrong for it in the presence of nullable changes.
We definitely first need to check this with a smaller isolated computation expression (= a trimmed down version of "monad"), to minimize the suspects.
8 remaining items
Add regression tests for #18034: FSharpPlus monad CE with nullness
Add regression tests for #18034: FSharpPlus monad CE with nullness
Fix nullness bugs: #17539, #18013, #18021, #18334, #19042
Fix nullness bugs: #17539, #18013, #18021, #18334, #19042
Fix nullness bugs: #17539, #18013, #18021, #18334, #19042
Fix nullness bugs: #17539, #18013, #18021, #18334, #19042
Fix nullness bugs: #17539, #18013, #18021, #18334, #19042
Fix nullness bugs: #17539, #18013, #18021, #18334, #19042
Fix nullness bugs: #17539, #18013, #18021, #18334, #19042
Fix nullness bugs: #17539, #18013, #18021, #18334, #19042
Fix nullness bugs: #17539, #18013, #18021, #18334, #19042
Fix nullness bugs: #17539, #18013, #18021, #18334, #19042
Fix nullness bugs: #17539, #18013, #18021, #18334, #19042
Fix nullness bugs: #17539, #18013, #18021, #18334, #19042
Bugfix :: Nullness :: Bug selection (#19262)