Skip to content

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

@Smaug123

Description

@Smaug123

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions