fsprojects / fantomas

FSharp source code formatter
https://fsprojects.github.io/fantomas
Other
772 stars 194 forks source link

Unexpected expression: Fixed #2112

Closed sergey-tihon closed 2 years ago

sergey-tihon commented 2 years ago

Issue created from fantomas-online

Code

use ptr = fixed data

Error

System.Exception: Unexpected expression: Fixed (Ident data, tmp.fsx (1,10--1,20))
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1439.Invoke(String message) in D:\a\_work\1\s\src\fsharp\FSharp.Core\printf.fs:line 1439
   at Fantomas.CodePrinter.genExpr(ASTContext astContext, SynExpr synExpr, Context ctx) in /_//src/Fantomas/CodePrinter.fs:line 2664
   at Fantomas.Context.shortExpressionWithFallback(FSharpFunc`2 shortExpression, FSharpFunc`2 fallbackExpression, Int32 maxWidth, FSharpOption`1 startColumn, Context ctx) in /_//src/Fantomas/Context.fs:line 852
   at Fantomas.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas/Context.fs:line 476
   at Fantomas.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas/Context.fs:line 476
   at Fantomas.Context.col[T](FSharpFunc`2 f', IEnumerable`1 c, FSharpFunc`2 f, Context ctx) in /_//src/Fantomas/Context.fs:line 581
   at Fantomas.CodePrinter.genImpFile@94-5.Invoke(Context ctx) in /_//src/Fantomas/CodePrinter.fs:line 94
   at Fantomas.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas/Context.fs:line 476
   at Fantomas.CodeFormatterImpl.formatWith(ParsedInput ast, FSharpList`1 defines, FSharpList`1 hashTokens, FormatContext formatContext, FormatConfig config) in /_//src/Fantomas/CodeFormatterImpl.fs:line 384
   at Fantomas.CodeFormatterImpl.format@403-3.Invoke(Unit unitVar) in /_//src/Fantomas/CodeFormatterImpl.fs:line 403
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 446
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 105

Problem description

Please describe here the Fantomas problem you encountered. Check out our Contribution Guidelines.

Extra information

Options

Fantomas master branch at 1/1/1990

Default Fantomas configuration

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

nojaf commented 2 years ago

Hello Sergey, thank you for reporting this issue.

I believe we don't support the https://fsharp.github.io/fsharp-compiler-docs/reference/fsharp-compiler-syntax-synexpr.html#Fixed expression.

We can probably add this to https://github.com/fsprojects/fantomas/blob/ab3b477bfca5c5d67960b841aa2dda46313eb790/src/Fantomas/SourceParser.fs#L572-L587 similar to the other expressions.

Are you interested in submitting a PR for this?

sergey-tihon commented 2 years ago

Here is bigger real-world code sample with fixed keyword

type BufferObject<'TDataType when 'TDataType : unmanaged>
    (gl:GL, data:'TDataType[], bufferType:BufferTargetARB) as self =

    let handle = gl.GenBuffer()
    do  self.Bind()
        use ptr = fixed data
        let size = unativeint <| (data.Length * sizeof<'TDataType>)
        gl.BufferData(bufferType, size , NativePtr.toVoidPtr ptr, BufferUsageARB.StaticDraw)

    member _.Bind() = gl.BindBuffer(bufferType, handle) 
    interface IDisposable with
        member this.Dispose() = gl.DeleteBuffer(handle)
sergey-tihon commented 2 years ago

@nojaf should I close this issue now or you do it during release ?

nojaf commented 2 years ago

Ah, usually, these get closed automatically when they are merged to the master branch. Your PR text didn't use a linked keyword, see https://github.com/fsprojects/fantomas/blob/master/CONTRIBUTING.md#pull-request-title and https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword

nojaf commented 2 years ago

Oh yeah and let me know if you want a release for this one.

sergey-tihon commented 2 years ago

No rush with it, so it can go with your usual release cycle