Opened 5 years ago

Closed 5 years ago

#10309 closed bug (fixed)

ApiAnnotations : mkGadtDecl discards annotations for HsFunTy

Reported by: alanz Owned by: alanz
Priority: normal Milestone: 7.10.2
Component: Compiler (Parser) Version: 7.10.1
Keywords: ApiAnnotations Cc: mpickering
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D848
Wiki Page:

Description

When mkGadtDecl is presented wih a HsFunTy it discards the SrcSpan, thus disconnecting any annotations on the HsFunTy.

mkGadtDecl names (L ls (HsForAllTy imp Nothing qvars cxt tau))
  = return $ mk_gadt_con names
  where
    (details, res_ty)           -- See Note [Sorting out the result type]
      = case tau of
          L _ (HsFunTy (L l (HsRecTy flds)) res_ty)
                                            -> (RecCon (L l flds), res_ty)
          _other                                    -> (PrefixCon [], tau)
...

This can be triggered by the following

{-# LANGUAGE GADTs #-}
module GADTRecords2 (H1(..)) where

-- | h1
data H1 a b where
  C3 :: (Num a) => { field :: a -- ^ hello docs
                   } -> H1 Int Int

Change History (5)

comment:1 Changed 5 years ago by alanz

This occurs for the HsFunTy which loses its SrcSpan. The only annotation at this level is an AnnRarrow.

        | btype '->'     ctype          {% ams (sLL $1 $> $ HsFunTy $1 $3)
                                               [mj AnnRarrow $2] }

One potential solution is the keep the annotation where it is, but also add it to $1, which will then only be used in tooling for the GADT case.

comment:2 Changed 5 years ago by alanz

Differential Rev(s): Phab:D848

comment:3 Changed 5 years ago by alanz

Status: newpatch

comment:4 Changed 5 years ago by Alan Zimmerman <alan.zimm@…>

In e4032b1951a35d8df63a74ebfee7449988b5ef40/ghc:

ApiAnnotations : mkGadtDecl discards annotations for HsFunTy

Summary:
When mkGadtDecl is presented wih a HsFunTy it discards the SrcSpan, thus
disconnecting any annotations on the HsFunTy.

```
mkGadtDecl names (L ls (HsForAllTy imp Nothing qvars cxt tau))
  = return $ mk_gadt_con names
  where
    (details, res_ty)           -- See Note [Sorting out the result type]
      = case tau of
          L _ (HsFunTy (L l (HsRecTy flds)) res_ty)
                                            -> (RecCon (L l flds), res_ty)
          _other                                    -> (PrefixCon [], tau)
...
```

This can be triggered by the following

```
{-# LANGUAGE GADTs #-}
module GADTRecords2 (H1(..)) where

-- | h1
data H1 a b where
  C3 :: (Num a) => { field :: a -- ^ hello docs
                   } -> H1 Int Int
```

Test Plan: ./validate

Reviewers: hvr, austin

Reviewed By: austin

Subscribers: bgamari, thomie, mpickering

Differential Revision: https://phabricator.haskell.org/D848

GHC Trac Issues: #10309

comment:5 Changed 5 years ago by thoughtpolice

Resolution: fixed
Status: patchclosed

Merged to ghc-7.10.

Note: See TracTickets for help on using tickets.