"Incomplete declaration of a static construct" which the F# compiler accepts
Issue created from fantomas-online
Code
type Foo =
{ Mem : unit -> unit }
static Empty: Foo =
{ Mem = (fun x -> failwith "Unimplemented function") }
Error
Fantomas.Core.ParseException: ParseException
[{ Severity = Error
SubCategory = "parse"
Range = Some (4,4--4,10)
ErrorNumber = Some 3862
Message =
"Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration." }]
at [email protected](Unit unitVar) in /_//src/Fantomas.Core/CodeFormatterImpl.fs:line 29
at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 508
at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 112
Problem description
The F# compiler accepts this, at least as of net8:
> dotnet fsi
Microsoft (R) F# Interactive version 12.8.0.0 for F# 8.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
> type Foo = { Bar : unit -> unit } with static Empty : Foo = { Bar = fun () -> () }
- ;;
type Foo =
{ Bar: (unit -> unit) }
static member Empty: Foo
Interestingly try.fsharp.org exhibits a similar failure, though.
(There's an obvious workaround, namely to add the keyword member.)
Extra information
- [ ] The formatted result breaks my code.
- [ ] The formatted result gives compiler warnings.
- [ ] I or my company would be willing to help fix this.
- [ ] I would like a release if this problem is solved.
Options
Fantomas main branch at 2023-12-29T14:09:11Z - a999b77ca5a024fbc3409955faac797e29b39d27
Default Fantomas configuration
Did you know that you can ignore files when formatting by using a .fantomasignore file? PS: It's unlikely that someone else will solve your specific issue, as it's something that you have a personal stake in.
I think this is related to https://github.com/dotnet/fsharp/pull/16345 So the net8 F# compiler is behind our parser code and still accepts this but won't anymore with the next bugfix release.
Yes, this fails in my fsi of my local dotnet/fsharp main branch.
This doesn't feel quite right if this code breaks in 8.0.200.