Skip to content

Commit d307587

Browse files
committed
Add Nullable and changes to compensate
1 parent 90249c1 commit d307587

File tree

20 files changed

+158
-127
lines changed

20 files changed

+158
-127
lines changed

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
-->
1313
<LangVersion>8.0</LangVersion>
1414
<LangVersion Condition="'$(TargetFramework)' == 'net9.0'">9.0</LangVersion>
15+
<Nullable Condition="'$(TargetFramework)' == 'net9.0'">enable</Nullable>
1516
<PaketPropsVersion>6.0.0</PaketPropsVersion> <!-- Hack to prevent paket from restoring when it should not -->
1617
</PropertyGroup>
1718
</Project>

src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskResultCE.fs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ module CancellableTaskResultCE =
5757
sm.ResumptionDynamicInfo.ResumptionData
5858
:?> ICriticalNotifyCompletion
5959

60-
assert not (isNull awaiter)
61-
6260
MethodBuilder.AwaitUnsafeOnCompleted(
6361
&sm.Data.MethodBuilder,
6462
&awaiter,
@@ -99,7 +97,7 @@ module CancellableTaskResultCE =
9997
(MoveNextMethodImpl<_>(fun sm ->
10098
//-- RESUMABLE CODE START
10199
__resumeAt sm.ResumptionPoint
102-
let mutable __stack_exn: Exception = null
100+
let mutable __stack_exn: ExceptionNull = null
103101

104102
try
105103
let __stack_code_fin = code.Invoke(&sm)
@@ -181,7 +179,7 @@ module CancellableTaskResultCE =
181179
(MoveNextMethodImpl<_>(fun sm ->
182180
//-- RESUMABLE CODE START
183181
__resumeAt sm.ResumptionPoint
184-
let mutable __stack_exn: Exception = null
182+
let mutable __stack_exn: ExceptionNull = null
185183

186184
try
187185
let __stack_code_fin = code.Invoke(&sm)

src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskValidationCE.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ module CancellableTaskValidationCE =
155155
(MoveNextMethodImpl<_>(fun sm ->
156156
//-- RESUMABLE CODE START
157157
__resumeAt sm.ResumptionPoint
158-
let mutable __stack_exn: Exception = null
158+
let mutable __stack_exn: ExceptionNull = null
159159

160160
try
161161
let __stack_code_fin = code.Invoke(&sm)

src/FsToolkit.ErrorHandling.JobResult/JobOptionCE.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module JobOptionCE =
7070
Job.tryFinallyFunDelay computation compensation
7171

7272
member inline _.Using
73-
(resource: 'T :> IDisposable, [<InlineIfLambda>] binder: 'T -> Job<_ option>)
73+
(resource: 'T :> IDisposableNull, [<InlineIfLambda>] binder: 'T -> Job<_ option>)
7474
: Job<_ option> =
7575
job.Using(resource, binder)
7676

src/FsToolkit.ErrorHandling.JobResult/JobResultCE.fs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,10 @@ module JobResultCE =
7575
Job.tryFinallyFunDelay computation compensation
7676

7777
member inline _.Using
78-
(resource: 'T :> IDisposable, [<InlineIfLambda>] binder: 'T -> Job<Result<'U, 'TError>>) : Job<
79-
Result<
80-
'U,
81-
'TError
82-
>
83-
>
84-
=
78+
(
79+
resource: 'T :> IDisposableNull,
80+
[<InlineIfLambda>] binder: 'T -> Job<Result<'U, 'TError>>
81+
) : Job<Result<'U, 'TError>> =
8582
job.Using(resource, binder)
8683

8784
member this.While

src/FsToolkit.ErrorHandling/AsyncResultOptionCE.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module AsyncResultOptionCE =
6565

6666
member inline this.Using
6767
(
68-
resource: 'ok :> IAsyncDisposable,
68+
resource: 'ok :> IAsyncDisposableNull,
6969
[<InlineIfLambda>] binder: 'ok -> AsyncResultOption<'okOut, 'error>
7070
) : AsyncResultOption<'okOut, 'error> =
7171
this.TryFinallyAsync(
Lines changed: 60 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,61 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<OutputType>Library</OutputType>
4-
<TargetFrameworks>net9.0;netstandard2.1;netstandard2.0</TargetFrameworks>
5-
<DebugType>portable</DebugType>
6-
<NoWarn>$(NoWarn);FS1204;FS3511;FS3513;FS0057</NoWarn>
7-
<PackageTags>$(PackageTags), fable-library, fable-dotnet, fable-javascript, fable-python</PackageTags>
8-
</PropertyGroup>
9-
<ItemGroup>
10-
<Compile Include="Result.fs" />
11-
<Compile Include="ResultCE.fs" />
12-
<Compile Include="ResultOp.fs" />
13-
<Compile Include="Option.fs" />
14-
<Compile Include="OptionCE.fs" />
15-
<Compile Include="OptionOp.fs" />
16-
<Compile Include="ResultOption.fs" />
17-
<Compile Include="ResultOptionCE.fs" />
18-
<Compile Include="ResultOptionOp.fs" />
19-
<Compile Include="Async.fs" />
20-
<Compile Include="Task.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
21-
<Compile Include="TaskOp.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
22-
<Compile Include="AsyncResult.fs" />
23-
<Compile Include="AsyncResultCE.fs" />
24-
<Compile Include="AsyncResultOp.fs" />
25-
<Compile Include="TaskResult.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
26-
<Compile Include="TaskResultCE.fs"
27-
Condition="'$(FABLE_COMPILER)' != 'true'" />
28-
<Compile Include="TaskResultOp.fs"
29-
Condition="'$(FABLE_COMPILER)' != 'true'" />
30-
<Compile Include="Validation.fs" />
31-
<Compile Include="ValidationOp.fs" />
32-
<Compile Include="ValidationCE.fs" />
33-
<Compile Include="AsyncValidation.fs" />
34-
<Compile Include="AsyncValidationOp.fs" />
35-
<Compile Include="AsyncValidationCE.fs" />
36-
<Compile Include="ValueOption.fs" />
37-
<Compile Include="ValueOptionCE.fs" />
38-
<Compile Include="AsyncOption.fs" />
39-
<Compile Include="AsyncOptionCE.fs" />
40-
<Compile Include="AsyncOptionOp.fs" />
41-
<Compile Include="TaskOption.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
42-
<Compile Include="TaskOptionCE.fs"
43-
Condition="'$(FABLE_COMPILER)' != 'true'" />
44-
<Compile Include="TaskOptionOp.fs"
45-
Condition="'$(FABLE_COMPILER)' != 'true'" />
46-
<Compile Include="AsyncResultOption.fs" />
47-
<Compile Include="AsyncResultOptionCE.fs" />
48-
<Compile Include="AsyncResultOptionOp.fs" />
49-
<Compile Include="TaskResultOption.fs"
50-
Condition="'$(FABLE_COMPILER)' != 'true'" />
51-
<Compile Include="TaskResultOptionCE.fs"
52-
Condition="'$(FABLE_COMPILER)' != 'true'" />
53-
<Compile Include="TaskResultOptionOp.fs"
54-
Condition="'$(FABLE_COMPILER)' != 'true'" />
55-
<Compile Include="List.fs" />
56-
<Compile Include="Array.fs" />
57-
<Compile Include="Seq.fs" />
58-
<None Include="Script.fsx" />
59-
<None Include="paket.references" />
60-
<Watch Include="@(None)" />
61-
</ItemGroup>
62-
<!-- Add source files to "fable" folder in Nuget package -->
63-
<ItemGroup>
64-
<Content Include="*.fsproj; **\*.fs" Exclude="Task.fs; **\Task*.fs" PackagePath="fable\" />
65-
</ItemGroup>
66-
<Import Project="..\..\.paket\Paket.Restore.targets" />
67-
</Project>
2+
<PropertyGroup>
3+
<OutputType>Library</OutputType>
4+
<TargetFrameworks>net9.0;netstandard2.1;netstandard2.0</TargetFrameworks>
5+
<DebugType>portable</DebugType>
6+
<NoWarn>$(NoWarn);FS1204;FS3511;FS3513;FS0057</NoWarn>
7+
<PackageTags>$(PackageTags), fable-library, fable-dotnet, fable-javascript, fable-python</PackageTags>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Include="Nullness.fs" />
11+
<Compile Include="Result.fs" />
12+
<Compile Include="ResultCE.fs" />
13+
<Compile Include="ResultOp.fs" />
14+
<Compile Include="Option.fs" />
15+
<Compile Include="OptionCE.fs" />
16+
<Compile Include="OptionOp.fs" />
17+
<Compile Include="ResultOption.fs" />
18+
<Compile Include="ResultOptionCE.fs" />
19+
<Compile Include="ResultOptionOp.fs" />
20+
<Compile Include="Async.fs" />
21+
<Compile Include="Task.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
22+
<Compile Include="TaskOp.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
23+
<Compile Include="AsyncResult.fs" />
24+
<Compile Include="AsyncResultCE.fs" />
25+
<Compile Include="AsyncResultOp.fs" />
26+
<Compile Include="TaskResult.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
27+
<Compile Include="TaskResultCE.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
28+
<Compile Include="TaskResultOp.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
29+
<Compile Include="Validation.fs" />
30+
<Compile Include="ValidationOp.fs" />
31+
<Compile Include="ValidationCE.fs" />
32+
<Compile Include="AsyncValidation.fs" />
33+
<Compile Include="AsyncValidationOp.fs" />
34+
<Compile Include="AsyncValidationCE.fs" />
35+
<Compile Include="ValueOption.fs" />
36+
<Compile Include="ValueOptionCE.fs" />
37+
<Compile Include="AsyncOption.fs" />
38+
<Compile Include="AsyncOptionCE.fs" />
39+
<Compile Include="AsyncOptionOp.fs" />
40+
<Compile Include="TaskOption.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
41+
<Compile Include="TaskOptionCE.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
42+
<Compile Include="TaskOptionOp.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
43+
<Compile Include="AsyncResultOption.fs" />
44+
<Compile Include="AsyncResultOptionCE.fs" />
45+
<Compile Include="AsyncResultOptionOp.fs" />
46+
<Compile Include="TaskResultOption.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
47+
<Compile Include="TaskResultOptionCE.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
48+
<Compile Include="TaskResultOptionOp.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
49+
<Compile Include="List.fs" />
50+
<Compile Include="Array.fs" />
51+
<Compile Include="Seq.fs" />
52+
<None Include="Script.fsx" />
53+
<None Include="paket.references" />
54+
<Watch Include="@(None)" />
55+
</ItemGroup>
56+
<!-- Add source files to "fable" folder in Nuget package -->
57+
<ItemGroup>
58+
<Content Include="*.fsproj; **\*.fs" Exclude="Task.fs; **\Task*.fs" PackagePath="fable\" />
59+
</ItemGroup>
60+
<Import Project="..\..\.paket\Paket.Restore.targets" />
61+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace FsToolkit.ErrorHandling
2+
open System
3+
4+
type ExceptionNull =
5+
#if NET9_0
6+
Exception | null
7+
#else
8+
Exception
9+
#endif
10+
11+
type IDisposableNull =
12+
#if NET9_0
13+
IDisposable | null
14+
#else
15+
IDisposable
16+
#endif
17+
18+
type IAsyncDisposableNull =
19+
#if NET9_0
20+
IAsyncDisposable | null
21+
#else
22+
IAsyncDisposable
23+
#endif

src/FsToolkit.ErrorHandling/OptionCE.fs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ module OptionCE =
1414
: 'output option =
1515
Option.bind binder input
1616

17-
// Could not get it to work solely with Source. In loop cases it would potentially match the #seq overload and ask for type annotation
18-
member inline this.Bind
19-
(m: 'input when 'input: null, [<InlineIfLambda>] binder: 'input -> 'output option)
20-
: 'output option =
21-
this.Bind(Option.ofObj m, binder)
2217

2318
member inline this.Zero() : unit option = this.Return()
2419

@@ -51,7 +46,7 @@ module OptionCE =
5146

5247
member inline this.Using
5348
(
54-
resource: 'disposable :> IDisposable,
49+
resource: 'disposable :> IDisposableNull,
5550
[<InlineIfLambda>] binder: 'disposable -> 'value option
5651
) : 'value option =
5752
this.TryFinally(
@@ -94,10 +89,6 @@ module OptionCE =
9489
: 'output option =
9590
Option.map mapper input
9691

97-
member inline _.BindReturn
98-
(x: 'input, [<InlineIfLambda>] f: 'input -> 'output)
99-
: 'output option =
100-
Option.map f (Option.ofObj x)
10192

10293
/// <summary>
10394
/// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type.
@@ -115,6 +106,19 @@ module OptionCE =
115106
module OptionExtensionsLower =
116107
type OptionBuilder with
117108

109+
110+
member inline _.BindReturn
111+
(x: 'input, [<InlineIfLambda>] f: 'input -> 'output)
112+
: 'output option =
113+
Option.map f (Option.ofObj x)
114+
115+
// Could not get it to work solely with Source. In loop cases it would potentially match the #seq overload and ask for type annotation
116+
member inline this.Bind
117+
(m: 'input when 'input: null, [<InlineIfLambda>] binder: 'input -> 'output option)
118+
: 'output option =
119+
this.Bind(Option.ofObj m, binder)
120+
121+
118122
member inline _.Source(nullableObj: 'value when 'value: null) : 'value option =
119123
Option.ofObj nullableObj
120124

src/FsToolkit.ErrorHandling/ResultCE.fs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ module ResultCE =
5858
compensation ()
5959

6060
member inline this.Using
61-
(resource: 'disposable :> IDisposable, binder: 'disposable -> Result<'ok, 'error>)
62-
: Result<'ok, 'error> =
61+
(resource: 'disposable :> IDisposableNull, binder: 'disposable -> Result<'ok, 'error>) : Result<
62+
'ok,
63+
'error
64+
>
65+
=
6366
this.TryFinally(
6467
(fun () -> binder resource),
6568
(fun () ->

0 commit comments

Comments
 (0)