Opened 3 years ago

Closed 3 years ago

#10255 closed bug (fixed)

API Annotations : ExprWithTySig processing discards annotated spans

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: Other Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D823
Wiki Page:

Description

In RdrHsSyn.checkAPat the processing for ExprWithTySig is defined as

   ExprWithTySig e t _ -> do e <- checkLPat msg e
                             -- Pattern signatures are parsed as sigtypes,
                             -- but they aren't explicit forall points.  Hence
                             -- we have to remove the implicit forall here.
                             let t' = case t of
                                        L _ (HsForAllTy Implicit _ _
                                             (L _ []) ty) -> ty
                                        other -> other
                             return (SigPatIn e (mkHsWithBndrs t'))

The t' variable ends up losing its original SrcSpan in the first case branch. This results in annotations becoming detached from the AST.

Change History (5)

comment:1 Changed 3 years ago by alanz

Potential solution: call mkHsWithBndrs with t' replaced by (L l (HsParTy t'))

comment:2 Changed 3 years ago by alanz

Differential Rev(s): Phab:D823

comment:3 Changed 3 years ago by alanz

Status: newpatch

comment:4 Changed 3 years ago by Austin Seipp <austin@…>

In 8dc294487fdaf102349c373c7db4796693573310/ghc:

API Annotations : ExprWithTySig processing discards annotated spans

In RdrHsSyn.checkAPat the processing for ExprWithTySig is defined as

   ExprWithTySig e t _ -> do e <- checkLPat msg e
                             -- Pattern signatures are parsed as sigtypes,
                             -- but they aren't explicit forall points.  Hence
                             -- we have to remove the implicit forall here.
                             let t' = case t of
                                        L _ (HsForAllTy Implicit _ _
                                             (L _ []) ty) -> ty
                                        other -> other
                             return (SigPatIn e (mkHsWithBndrs t'))

The t' variable ends up losing its original SrcSpan in the first case
branch. This results in annotations becoming detached from the AST.

Reviewed By: austin

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

GHC Trac Issues: #10255

comment:5 Changed 3 years ago by ezyang

Resolution: fixed
Status: patchclosed

Thank you for submitting useful patches fixing subtle mistakes that were made in location handling code!

Note: See TracTickets for help on using tickets.