Skip to content

Commit 57fb06c

Browse files
authored
First pass F# 9 support and nullness (#308)
* First pass F# 9 support * Add Nullable and changes to compensate * Keep fantomas from having a stroke * support fable * Update ValueOption/Option CE for F# 9 nullness * Fix fable * Format the world * fix devcontainer * Add ValueOption tests for fable
1 parent e72eff3 commit 57fb06c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+338
-451
lines changed

.config/dotnet-tools.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"paket": {
6-
"version": "8.0.3",
6+
"version": "9.0.2",
77
"commands": [
88
"paket"
99
],
@@ -17,7 +17,7 @@
1717
"rollForward": false
1818
},
1919
"fantomas": {
20-
"version": "6.3.16",
20+
"version": "7.0.0",
2121
"commands": [
2222
"fantomas"
2323
],

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"ghcr.io/devcontainers-contrib/features/starship:1": {},
2424
// https://github.com/devcontainers/features/blob/main/src/dotnet/README.md
2525
"ghcr.io/devcontainers/features/dotnet:2": {
26-
"version": "8.0",
27-
"additionalVersions": "7.0,6.0"
26+
"version": "9.0",
27+
"additionalVersions": "8.0"
2828
},
2929
"ghcr.io/devcontainers/features/node:1": {
3030
"version": "18"

.fantomasignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
AssemblyInfo.fs
22
tests/FsToolkit.ErrorHandling.AsyncSeq.Tests/Main.fs
3-
tests/FsToolkit.ErrorHandling.Tests/Main.fs
3+
tests/FsToolkit.ErrorHandling.Tests/Main.fs

.paket/Paket.Restore.targets

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,15 @@
235235
<Splits>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',').Length)</Splits>
236236
<PackageName>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[0])</PackageName>
237237
<PackageVersion>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[1])</PackageVersion>
238+
<Reference>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[2])</Reference>
238239
<AllPrivateAssets>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[4])</AllPrivateAssets>
239240
<CopyLocal Condition="%(PaketReferencesFileLinesInfo.Splits) &gt;= 6">$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[5])</CopyLocal>
240241
<OmitContent Condition="%(PaketReferencesFileLinesInfo.Splits) &gt;= 7">$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[6])</OmitContent>
241242
<ImportTargets Condition="%(PaketReferencesFileLinesInfo.Splits) &gt;= 8">$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[7])</ImportTargets>
242243
<Aliases Condition="%(PaketReferencesFileLinesInfo.Splits) &gt;= 9">$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[8])</Aliases>
243244
</PaketReferencesFileLinesInfo>
244-
<PackageReference Include="%(PaketReferencesFileLinesInfo.PackageName)">
245-
<Version>%(PaketReferencesFileLinesInfo.PackageVersion)</Version>
245+
<PackageReference Condition=" '$(ManagePackageVersionsCentrally)' != 'true' Or '%(PaketReferencesFileLinesInfo.Reference)' == 'Direct' " Include="%(PaketReferencesFileLinesInfo.PackageName)">
246+
<Version Condition=" '$(ManagePackageVersionsCentrally)' != 'true' ">%(PaketReferencesFileLinesInfo.PackageVersion)</Version>
246247
<PrivateAssets Condition=" ('%(PaketReferencesFileLinesInfo.AllPrivateAssets)' == 'true') Or ('$(PackAsTool)' == 'true') ">All</PrivateAssets>
247248
<ExcludeAssets Condition=" %(PaketReferencesFileLinesInfo.CopyLocal) == 'false' or %(PaketReferencesFileLinesInfo.AllPrivateAssets) == 'exclude'">runtime</ExcludeAssets>
248249
<ExcludeAssets Condition=" %(PaketReferencesFileLinesInfo.OmitContent) == 'true'">$(ExcludeAssets);contentFiles</ExcludeAssets>
@@ -252,6 +253,10 @@
252253
<AllowExplicitVersion>true</AllowExplicitVersion>
253254

254255
</PackageReference>
256+
257+
<PackageVersion Include="%(PaketReferencesFileLinesInfo.PackageName)">
258+
<Version>%(PaketReferencesFileLinesInfo.PackageVersion)</Version>
259+
</PackageVersion>
255260
</ItemGroup>
256261

257262
<PropertyGroup>

.vscode/settings.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
22
"editor.inlayHints.enabled": "off",
33
"FSharp.enableMSBuildProjectGraph": true,
4-
"editor.formatOnSave": true,
4+
"[fsharp]": {
5+
"editor.formatOnSave": true,
6+
},
57
"FSharp.notifications.trace": false,
68
"FSharp.notifications.traceNamespaces": [
79
"BoundModel.TypeCheck",
810
"BackgroundCompiler."
911
],
1012
"FSharp.fsac.parallelReferenceResolution": false,
1113
"FSharp.enableAnalyzers": true,
12-
"FSharp.analyzersPath": ["packages/analyzers"]
13-
}
14+
"FSharp.analyzersPath": [
15+
"packages/analyzers"
16+
]
17+
}

Directory.Build.props

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
<Project>
22
<PropertyGroup>
33
<DisableCheckingDuplicateNuGetItems>true</DisableCheckingDuplicateNuGetItems>
4-
<NoWarn>$(NoWarn);FS2003; NU1903; NU1904</NoWarn>
4+
<NoWarn>$(NoWarn);FS2003;NU1903;NU1904;FS0057</NoWarn>
55
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
66
<WarningsAsErrors />
7+
<!--
8+
Changing the LangVersion based on TFM because F# 9 brings in new features that older SDK's can't support.
9+
See https://github.com/dotnet/fsharp/issues/14313 for an example.
10+
To keep this library as backward compatible as possible we're setting the LangVersion to 8.0 by default.
11+
Then, we're assuming if you're building for net9.0 you're using F# 9 Language features.
12+
-->
13+
<LangVersion>8.0</LangVersion>
14+
<LangVersion Condition="'$(TargetFramework)' == 'net9.0'">9.0</LangVersion>
15+
<Nullable Condition="'$(TargetFramework)' == 'net9.0'">enable</Nullable>
16+
<PaketPropsVersion>6.0.0</PaketPropsVersion> <!-- Hack to prevent paket from restoring when it should not -->
717
</PropertyGroup>
818
</Project>

Directory.Solution.targets

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<Project>
2-
<Target Name="ToolRestore" BeforeTargets="Restore;CollectPackageReferences">
3-
<Exec Command="dotnet tool restore" StandardOutputImportance="High"
4-
StandardErrorImportance="High" />
2+
<PropertyGroup>
3+
<_BuildProjBaseIntermediateOutputPath>$(MSBuildThisFileDirectory)build/obj/</_BuildProjBaseIntermediateOutputPath>
4+
<_DotnetToolManifestFile>$(MSBuildThisFileDirectory).config/dotnet-tools.json</_DotnetToolManifestFile>
5+
<_DotnetToolRestoreOutputFile>$(_BuildProjBaseIntermediateOutputPath)/dotnet-tool-restore-$(NETCoreSdkVersion)-$(OS)</_DotnetToolRestoreOutputFile>
6+
</PropertyGroup>
7+
8+
<Target Name="ToolRestore" BeforeTargets="Restore;CollectPackageReferences;PaketRestore" Inputs="$(_DotnetToolManifestFile)" Outputs="$(_DotnetToolRestoreOutputFile)">
9+
<Exec Command="dotnet tool restore" WorkingDirectory="$(MSBuildThisFileDirectory)" StandardOutputImportance="High" StandardErrorImportance="High" />
10+
<MakeDir Directories="$(_BuildProjBaseIntermediateOutputPath)"/>
11+
<Touch Files="$(_DotnetToolRestoreOutputFile)" AlwaysCreate="True" ForceTouch="True" />
512
</Target>
613
</Project>

benchmarks/benchmarks.fsproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
55
<OutputType>Exe</OutputType>
6-
<LangVersion>preview</LangVersion>
76
</PropertyGroup>
87
<PropertyGroup>
98
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -14,9 +13,6 @@
1413
<IsPackable>false</IsPackable>
1514
<NoWarn>FS1204;FS3501;FS3511</NoWarn>
1615
</PropertyGroup>
17-
<PropertyGroup Condition="'$(Configuration)'=='Release'">
18-
<Tailcalls>true</Tailcalls>
19-
</PropertyGroup>
2016
<ItemGroup>
2117
<Compile Include="SeqTests.fs" />
2218
<Compile Include="ApplicativeTests.fs" />
@@ -28,7 +24,8 @@
2824
<Compile Include="Program.fs" />
2925
</ItemGroup>
3026
<ItemGroup>
31-
<ProjectReference Include="..\src\FsToolkit.ErrorHandling.JobResult\FsToolkit.ErrorHandling.JobResult.fsproj" />
27+
<ProjectReference
28+
Include="..\src\FsToolkit.ErrorHandling.JobResult\FsToolkit.ErrorHandling.JobResult.fsproj" />
3229
</ItemGroup>
3330
<Import Project="..\.paket\Paket.Restore.targets" />
3431
</Project>

build/build.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ let formatCode _ =
146146
Trace.traceErrorfn "Errors while formatting all files: %A" result.Messages
147147

148148
let analyze _ =
149-
let analyzerPaths = !! "packages/analyzers/**/analyzers/dotnet/fs"
149+
let analyzerPaths = !!"packages/analyzers/**/analyzers/dotnet/fs"
150150

151151
let createArgsForProject (project: string) analyzerPaths =
152152
let projectName = Path.GetFileNameWithoutExtension project
@@ -162,7 +162,7 @@ let analyze _ =
162162
]
163163
|> String.concat " "
164164

165-
!! "src/**/*.fsproj"
165+
!!"src/**/*.fsproj"
166166
|> Seq.iter (fun fsproj ->
167167
let result =
168168
createArgsForProject fsproj analyzerPaths
@@ -187,7 +187,7 @@ let checkFormatCode _ =
187187

188188

189189
let clean _ =
190-
!! "bin"
190+
!!"bin"
191191
++ "benchmarks/**/bin"
192192
++ "src/**/bin"
193193
++ "tests/**/bin"

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.100",
3+
"version": "9.0.100",
44
"rollForward": "latestMinor"
55
}
66
}

src/Directory.Build.props

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
</PropertyGroup>
2424

2525
<PropertyGroup>
26-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
27-
<WarningsAsErrors />
28-
<NoWarn>FS2003</NoWarn>
26+
<NoWarn>$(NoWarn);FS2003</NoWarn>
2927
</PropertyGroup>
3028
</Project>

src/FsToolkit.ErrorHandling.AsyncSeq/FsToolkit.ErrorHandling.AsyncSeq.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<OutputType>Library</OutputType>
5-
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
6-
<LangVersion>preview</LangVersion>
5+
<TargetFrameworks>netstandard2.1;netstandard2.0;net9.0</TargetFrameworks>
6+
77
<DebugType>portable</DebugType>
88
</PropertyGroup>
99
<!-- Add source files to "fable" folder in Nuget package -->

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: 3 additions & 5 deletions
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)
@@ -236,10 +236,8 @@ module AsyncExtensions =
236236
this.ReturnFrom(Async.AwaitCancellableTask t)
237237

238238
member inline this.Bind
239-
([<InlineIfLambda>] t: CancellableTask, [<InlineIfLambda>] binder: (unit -> Async<'U>)) : Async<
240-
'U
241-
>
242-
=
239+
([<InlineIfLambda>] t: CancellableTask, [<InlineIfLambda>] binder: (unit -> Async<'U>))
240+
: Async<'U> =
243241
this.Bind(Async.AwaitCancellableTask t, binder)
244242

245243
member inline this.ReturnFrom([<InlineIfLambda>] t: CancellableTask) : Async<unit> =

src/FsToolkit.ErrorHandling.IcedTasks/FsToolkit.ErrorHandling.IcedTasks.fsproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<OutputType>Library</OutputType>
5-
<TargetFrameworks>net6.0;netstandard2.0;netstandard2.1</TargetFrameworks>
6-
<LangVersion>preview</LangVersion>
5+
<TargetFrameworks>net6.0;netstandard2.0;netstandard2.1;net9.0</TargetFrameworks>
6+
77
<DebugType>portable</DebugType>
8-
<NoWarn>FS3511;FS3513</NoWarn>
8+
<NoWarn>$(NoWarn);FS3511;FS3513</NoWarn>
99
</PropertyGroup>
1010
<ItemGroup>
1111
<Compile Include="CancellableTaskResultBuilderBase.fs" />

src/FsToolkit.ErrorHandling.JobResult/FsToolkit.ErrorHandling.JobResult.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<OutputType>Library</OutputType>
5-
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
5+
<TargetFrameworks>netstandard2.1;netstandard2.0;net9.0</TargetFrameworks>
66
<DebugType>portable</DebugType>
77
</PropertyGroup>
88
<ItemGroup>

src/FsToolkit.ErrorHandling.JobResult/JobOptionCE.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ module JobOptionCE =
1010
type JobOptionBuilder() =
1111

1212
member inline _.Return(value: 'T) : Job<_ option> =
13-
option.Return value
13+
Some value
1414
|> job.Return
1515

1616
member inline _.ReturnFrom(jobResult: Job<_ option>) : Job<_ option> = jobResult
1717

1818
member inline _.Zero() : Job<_ option> =
19-
option.Zero()
19+
Some()
2020
|> job.Return
2121

2222
member inline _.Bind
@@ -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: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,8 @@ module JobResultCE =
5858
Job.tryWithDelay computation handler
5959

6060
member inline _.TryFinally
61-
(computation: Job<Result<'T, 'TError>>, [<InlineIfLambda>] compensation: unit -> unit) : Job<
62-
Result<
63-
'T,
64-
'TError
65-
>
66-
>
67-
=
61+
(computation: Job<Result<'T, 'TError>>, [<InlineIfLambda>] compensation: unit -> unit)
62+
: Job<Result<'T, 'TError>> =
6863
Job.tryFinallyFun computation compensation
6964

7065
member inline _.TryFinally
@@ -75,13 +70,10 @@ module JobResultCE =
7570
Job.tryFinallyFunDelay computation compensation
7671

7772
member inline _.Using
78-
(resource: 'T :> IDisposable, [<InlineIfLambda>] binder: 'T -> Job<Result<'U, 'TError>>) : Job<
79-
Result<
80-
'U,
81-
'TError
82-
>
83-
>
84-
=
73+
(
74+
resource: 'T :> IDisposableNull,
75+
[<InlineIfLambda>] binder: 'T -> Job<Result<'U, 'TError>>
76+
) : Job<Result<'U, 'TError>> =
8577
job.Using(resource, binder)
8678

8779
member this.While

src/FsToolkit.ErrorHandling/AsyncOptionCE.fs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module AsyncOptionCE =
1212
member inline _.ReturnFrom(value: Async<'value option>) : Async<'value option> = value
1313

1414
member inline _.Zero() : Async<unit option> =
15-
option.Zero()
15+
Some()
1616
|> async.Return
1717

1818
member inline _.Bind
@@ -43,10 +43,8 @@ module AsyncOptionCE =
4343
async.TryFinally(computation, compensation)
4444
#if !FABLE_COMPILER
4545
member inline _.TryFinallyAsync
46-
(computation: Async<'value option>, [<InlineIfLambda>] compensation: unit -> ValueTask) : Async<
47-
'value option
48-
>
49-
=
46+
(computation: Async<'value option>, [<InlineIfLambda>] compensation: unit -> ValueTask)
47+
: Async<'value option> =
5048
let compensation =
5149
async {
5250
let vTask = compensation ()

src/FsToolkit.ErrorHandling/AsyncResultCE.fs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,8 @@ module AsyncResultCE =
4646
async.TryWith(computation, handler)
4747

4848
member inline _.TryFinally
49-
(computation: Async<Result<'ok, 'error>>, [<InlineIfLambda>] compensation: unit -> unit) : Async<
50-
Result<
51-
'ok,
52-
'error
53-
>
54-
>
55-
=
49+
(computation: Async<Result<'ok, 'error>>, [<InlineIfLambda>] compensation: unit -> unit)
50+
: Async<Result<'ok, 'error>> =
5651
async.TryFinally(computation, compensation)
5752
#if !FABLE_COMPILER
5853
member inline _.TryFinallyAsync

0 commit comments

Comments
 (0)