Skip to content
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

"Incomplete declaration of a static construct" which the F# compiler accepts #3033

Open
4 tasks
Smaug123 opened this issue Dec 30, 2023 · 2 comments
Open
4 tasks

Comments

@Smaug123
Copy link
Contributor

Smaug123 commented Dec 30, 2023

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 Fantomas.Core.CodeFormatterImpl.parse@24.Invoke(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 - a999b77

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.

@dawedawe
Copy link
Member

dawedawe commented Jan 2, 2024

I think this is related to dotnet/fsharp#16345
So the net8 F# compiler is behind our parser code and still accepts this but won't anymore with the next bugfix release.

@nojaf
Copy link
Contributor

nojaf commented Jan 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants