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

Inline comment to the last constructor disapears #425

Open
Lev135 opened this issue Nov 6, 2022 · 1 comment · May be fixed by #427
Open

Inline comment to the last constructor disapears #425

Lev135 opened this issue Nov 6, 2022 · 1 comment · May be fixed by #427

Comments

@Lev135
Copy link
Contributor

Lev135 commented Nov 6, 2022

(with stylish-haskell 0.14.3.0):
It happens with enums, constructor with fields and records:

data Foo
  = Foo -- ^ foo
  | Bar -- ^ bar
  | Baz -- ^ baz

data Foo'
  = Foo' Int -- ^ foo
  | Bar' Int -- ^ bar
  | Baz' Int -- ^ baz

data Foo''
  = Foo''
  { foo :: Int
  }
  -- ^ foo
  | Bar''
  { bar :: Int
  }
  -- ^ bar
  | Baz''
  { baz :: Int
  }
  -- ^ baz

after stylish:

data Foo
  = Foo -- ^ foo
  | Bar -- ^ bar
  | Baz

data Foo'
  = Foo' Int -- ^ foo
  | Bar' Int -- ^ bar
  | Baz' Int

data Foo''
  = Foo''
  { foo :: Int
  }
  -- ^ foo
  | Bar''
  { bar :: Int
  }
  -- ^ bar
  | Baz''
  { baz :: Int
  }
@Lev135
Copy link
Contributor Author

Lev135 commented Nov 6, 2022

I added a trace show in step function and I saw the following:

The reason is maybe that in GHC module structure last comment is in separate place:

data Foo
  = Foo -- ^ foo
  | Bar -- ^ bar
  | Baz -- ^ baz
L { abstract:SrcSpan }
    ( HsModule
        ( EpAnn
            ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
            ( AnnsModule ""
                ( AnnList Nothing Nothing Nothing "" "" )
            )
            ( EpaCommentsBalanced ""
                [ L
                    ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                    ( EpaComment EpaEofComment { abstract:RealSrcSpan } )
                ]
            )
        )
        ( VirtualBraces 1 ) Nothing Nothing ""
        [ L
            ( SrcSpanAnn
                ( EpAnn
                    ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                    ( AnnListItem "" )
                    ( EpaComments
                        [ L
                            ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                            ( EpaComment
                                ( EpaLineComment "-- ^ baz" ) { abstract:RealSrcSpan }
                            )
                        ]
                    )
                ) { abstract:SrcSpan }
            )
            ( TyClD NoExtField
                ( DataDecl
                    ( EpAnn
                        ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                        [ AddEpAnn AnnData
                            ( EpaSpan { abstract:RealSrcSpan } )
                        , AddEpAnn AnnEqual
                            ( EpaSpan { abstract:RealSrcSpan } )
                        ]
                        ( EpaComments
                            [ L
                                ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                                ( EpaComment
                                    ( EpaLineComment "-- ^ bar" ) { abstract:RealSrcSpan }
                                )
                            , L
                                ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                                ( EpaComment
                                    ( EpaLineComment "-- ^ foo" ) { abstract:RealSrcSpan }
                                )
                            ]
                        )
                    )
                    ( L
                        ( SrcSpanAnn EpAnnNotUsed { abstract:SrcSpan } )
                        ( Unqual { abstract:OccName } )
                    )
                    ( HsQTvs NoExtField "" ) Prefix
                    ( HsDataDefn NoExtField DataType Nothing Nothing Nothing
                        [ L
                            ( SrcSpanAnn
                                ( EpAnn
                                    ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                                    ( AnnListItem
                                        [ AddVbarAnn
                                            ( EpaSpan { abstract:RealSrcSpan } )
                                        ]
                                    )
                                    ( EpaComments "" )
                                ) { abstract:SrcSpan }
                            )
                            ( ConDeclH98
                                ( EpAnn
                                    ( Anchor { abstract:RealSrcSpan } UnchangedAnchor ) ""
                                    ( EpaComments "" )
                                )
                                ( L
                                    ( SrcSpanAnn EpAnnNotUsed { abstract:SrcSpan } )
                                    ( Unqual { abstract:OccName } )
                                ) False "" Nothing
                                ( PrefixCon "" "" ) Nothing
                            )
                        , L
                            ( SrcSpanAnn
                                ( EpAnn
                                    ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                                    ( AnnListItem
                                        [ AddVbarAnn
                                            ( EpaSpan { abstract:RealSrcSpan } )
                                        ]
                                    )
                                    ( EpaComments "" )
                                ) { abstract:SrcSpan }
                            )
                            ( ConDeclH98
                                ( EpAnn
                                    ( Anchor { abstract:RealSrcSpan } UnchangedAnchor ) ""
                                    ( EpaComments "" )
                                )
                                ( L
                                    ( SrcSpanAnn EpAnnNotUsed { abstract:SrcSpan } )
                                    ( Unqual { abstract:OccName } )
                                ) False "" Nothing
                                ( PrefixCon "" "" ) Nothing
                            )
                        , L
                            ( SrcSpanAnn EpAnnNotUsed { abstract:SrcSpan } )
                            ( ConDeclH98
                                ( EpAnn
                                    ( Anchor { abstract:RealSrcSpan } UnchangedAnchor ) ""
                                    ( EpaComments "" )
                                )
                                ( L
                                    ( SrcSpanAnn EpAnnNotUsed { abstract:SrcSpan } )
                                    ( Unqual { abstract:OccName } )
                                ) False "" Nothing
                                ( PrefixCon "" "" ) Nothing
                            )
                        ] ""
                    )
                )
            )
        ] Nothing Nothing
    )

compare with standalone comments (for wich we have correct behavior):

data Foo
  -- | foo
  = Foo
  -- | Bar
  | Bar
  -- | Baz
  | Baz
L { abstract:SrcSpan }
    ( HsModule
        ( EpAnn
            ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
            ( AnnsModule ""
                ( AnnList Nothing Nothing Nothing "" "" )
            )
            ( EpaCommentsBalanced ""
                [ L
                    ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                    ( EpaComment EpaEofComment { abstract:RealSrcSpan } )
                ]
            )
        )
        ( VirtualBraces 1 ) Nothing Nothing ""
        [ L
            ( SrcSpanAnn
                ( EpAnn
                    ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                    ( AnnListItem "" )
                    ( EpaComments "" )
                ) { abstract:SrcSpan }
            )
            ( TyClD NoExtField
                ( DataDecl
                    ( EpAnn
                        ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                        [ AddEpAnn AnnData
                            ( EpaSpan { abstract:RealSrcSpan } )
                        , AddEpAnn AnnEqual
                            ( EpaSpan { abstract:RealSrcSpan } )
                        ]
                        ( EpaComments
                            [ L
                                ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                                ( EpaComment
                                    ( EpaLineComment "-- | baz" ) { abstract:RealSrcSpan }
                                )
                            , L
                                ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                                ( EpaComment
                                    ( EpaLineComment "-- | bar" ) { abstract:RealSrcSpan }
                                )
                            , L
                                ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                                ( EpaComment
                                    ( EpaLineComment "-- | foo" ) { abstract:RealSrcSpan }
                                )
                            ]
                        )
                    )
                    ( L
                        ( SrcSpanAnn EpAnnNotUsed { abstract:SrcSpan } )
                        ( Unqual { abstract:OccName } )
                    )
                    ( HsQTvs NoExtField "" ) Prefix
                    ( HsDataDefn NoExtField DataType Nothing Nothing Nothing
                        [ L
                            ( SrcSpanAnn
                                ( EpAnn
                                    ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                                    ( AnnListItem
                                        [ AddVbarAnn
                                            ( EpaSpan { abstract:RealSrcSpan } )
                                        ]
                                    )
                                    ( EpaComments "" )
                                ) { abstract:SrcSpan }
                            )
                            ( ConDeclH98
                                ( EpAnn
                                    ( Anchor { abstract:RealSrcSpan } UnchangedAnchor ) ""
                                    ( EpaComments "" )
                                )
                                ( L
                                    ( SrcSpanAnn EpAnnNotUsed { abstract:SrcSpan } )
                                    ( Unqual { abstract:OccName } )
                                ) False "" Nothing
                                ( PrefixCon "" "" ) Nothing
                            )
                        , L
                            ( SrcSpanAnn
                                ( EpAnn
                                    ( Anchor { abstract:RealSrcSpan } UnchangedAnchor )
                                    ( AnnListItem
                                        [ AddVbarAnn
                                            ( EpaSpan { abstract:RealSrcSpan } )
                                        ]
                                    )
                                    ( EpaComments "" )
                                ) { abstract:SrcSpan }
                            )
                            ( ConDeclH98
                                ( EpAnn
                                    ( Anchor { abstract:RealSrcSpan } UnchangedAnchor ) ""
                                    ( EpaComments "" )
                                )
                                ( L
                                    ( SrcSpanAnn EpAnnNotUsed { abstract:SrcSpan } )
                                    ( Unqual { abstract:OccName } )
                                ) False "" Nothing
                                ( PrefixCon "" "" ) Nothing
                            )
                        , L
                            ( SrcSpanAnn EpAnnNotUsed { abstract:SrcSpan } )
                            ( ConDeclH98
                                ( EpAnn
                                    ( Anchor { abstract:RealSrcSpan } UnchangedAnchor ) ""
                                    ( EpaComments "" )
                                )
                                ( L
                                    ( SrcSpanAnn EpAnnNotUsed { abstract:SrcSpan } )
                                    ( Unqual { abstract:OccName } )
                                ) False "" Nothing
                                ( PrefixCon "" "" ) Nothing
                            )
                        ] ""
                    )
                )
            )
        ] Nothing Nothing
    )

Maybe its a GHC parser bug. It seems for me, that the last comment isn't attached to record constructor at all. But I'm very likely to be wrong: I know nothing about GHC internal stucture, that's only what I can guess by theese two examples. Maybe someone more skilled can say something more.

@Lev135 Lev135 changed the title Post comment to the last constructor disapears Inline comment to the last constructor disapears Nov 6, 2022
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

Successfully merging a pull request may close this issue.

1 participant