Opened 3 years ago

Closed 3 years ago

#10278 closed bug (fixed)

ApiAnnotations : Nested forall loses forall annotation

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:D833,Phab:D836
Wiki Page:

Description

When parsing

{-# LANGUAGE ScopedTypeVariables #-}

extremumNewton :: forall tag. forall tag1.
                   tag -> tag1 -> Int
extremumNewton = undefined

The parser attaches an AnnForall to the second forall, which appears as a nested HsForAllTy.

Somewhere this nesting is flattened, and the tyvarbndrs are collapsed into a single HsForAllTy. In this process the second AnnForAll loses its anchor in the AST.

Change History (7)

comment:1 Changed 3 years ago by alanz

@jstolarek has pointed out that the offending function is HsTypes.mk_forall_ty

comment:2 Changed 3 years ago by alanz

Differential Rev(s): Phab:D833

comment:3 Changed 3 years ago by alanz

Status: newpatch

Although there is a version in development that gets rid of the collapsing, I am not going to have time to chase the last bugs through in the near future, and the Phab:D833 version will get the job done for ghc-exactprint in the interim.

comment:4 Changed 3 years ago by alanz

Differential Rev(s): Phab:D833Phab:D833,Phab:D836

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

In 81030ede73c4e3783219b2a8d7463524e847cfce/ghc:

ApiAnnotations : Nested forall loses forall annotation

When parsing

    {-# LANGUAGE ScopedTypeVariables #-}

    extremumNewton :: forall tag. forall tag1.
                       tag -> tag1 -> Int
    extremumNewton = undefined

The parser attaches an AnnForall to the second forall, which appears as
a nested HsForAllTy.

Somewhere this nesting is flattened, and the tyvarbndrs are collapsed
into a single HsForAllTy. In this process the second AnnForAll loses its
anchor in the AST.

Reviewed By: austin

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

GHC Trac Issues: #10278

comment:6 Changed 3 years ago by Alan Zimmerman <alan.zimm@…>

In c553e980e4a5d149af13bb705ec02819a15937ee/ghc:

ApiAnnotations : AST version of nested forall loses forall annotation

Summary:
When parsing

    {-# LANGUAGE ScopedTypeVariables #-}

    extremumNewton :: forall tag. forall tag1.
                       tag -> tag1 -> Int
    extremumNewton = undefined

the parser creates nested HsForAllTy's for the two forall statements.

These get flattened into a single one in `HsTypes.mk_forall_ty`

This patch removes the flattening, so that API Annotations are not lost in the
process.

Test Plan: ./validate

Reviewers: goldfire, austin, simonpj

Reviewed By: simonpj

Subscribers: bgamari, mpickering, thomie, goldfire

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

GHC Trac Issues: #10278, #10315, #10354, #10363

comment:7 Changed 3 years ago by thoughtpolice

Resolution: fixed
Status: patchclosed

Merged to ghc-7.10.

Note: See TracTickets for help on using tickets.