dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.94k stars 788 forks source link

Atomic list index syntax is marked as NonAtomic #12309

Open nojaf opened 3 years ago

nojaf commented 3 years ago

I'm not entirely sure but when I have the following code:

let y = [ 0; 2; 4 ][1]

I get

App
    (NonAtomic, false,
     ArrayOrListComputed
       (false,
        Sequential
          (SuppressNeither, true,
           Const (Int32 0, tmp.fsx (1,10--1,11)),
           Sequential
             (SuppressNeither, true,
              Const (Int32 2, tmp.fsx (1,13--1,14)),
              Const (Int32 4, tmp.fsx (1,16--1,17)),
              tmp.fsx (1,13--1,17)), tmp.fsx (1,10--1,17)),
        tmp.fsx (1,8--1,19)),
     ArrayOrListComputed
       (false, Const (Int32 1, tmp.fsx (1,20--1,21)),
        tmp.fsx (1,19--1,22)), tmp.fsx (1,8--1,22))

Expected behavior

I was expecting App(Atomic, false, ...)

Actual behavior

TheSynExpr.App contains NonAtomic while inside fsi I get:

image

Known workarounds

/

Related information

Provide any related information (optional):

FCS 41.0.0-preview.21472.3

//cc @dsyme

dsyme commented 3 years ago

Yes, this case is handled separately in CheckExpressions.fs, based on ranges. See isAdjacentListExpr in CheckExpressions.fs.

So I think you have to do the same in fantomas.

dsyme commented 3 years ago

I'll mark as "feature improvement" because we could add an API for this logic.

nojaf commented 3 years ago

Or would it be possible to capture this in its own SynExpr union instead of reusing SynExpr.App? Just thinking out loud though.