Ticket #7827: 0001-Fix-type-variable-scoping-in-nested-pattern-type-sig.patch

File 0001-Fix-type-variable-scoping-in-nested-pattern-type-sig.patch, 1.5 KB (added by parcs, 13 months ago)
  • compiler/rename/RnPat.lhs

    From 93bdd383cfefdfd8627f0384f987161411279320 Mon Sep 17 00:00:00 2001
    From: Patrick Palka <patrick@parcs.ath.cx>
    Date: Thu, 11 Apr 2013 14:00:51 -0400
    Subject: [PATCH] Fix type variable scoping in nested pattern type signatures
     (#7827)
    
    ---
     compiler/rename/RnPat.lhs |   13 +++++++++++--
     1 file changed, 11 insertions(+), 2 deletions(-)
    
    diff --git a/compiler/rename/RnPat.lhs b/compiler/rename/RnPat.lhs
    index a039f36..617c6be 100644
    a b rnPatAndThen mk (VarPat rdr) = do { loc <- liftCps getSrcSpanM 
    330330     -- (e.g. in the pattern (x, x -> y) x needs to be bound in the rhs of the tuple) 
    331331                                      
    332332rnPatAndThen mk (SigPatIn pat sig) 
    333   = do { pat' <- rnLPatAndThen mk pat 
    334        ; sig' <- rnHsSigCps sig 
     333  -- When renaming a pattern type signature (e.g. f (a :: T) = ...), it is 
     334  -- important to rename its type signature _before_ renaming the rest of the 
     335  -- pattern, so that type variables are first bound by the _outermost_ pattern 
     336  -- type signature they occur in. This keeps the type checker happy when 
     337  -- pattern type signatures happen to be nested (#7827) 
     338  -- 
     339  -- f ((Just (x :: a) :: Maybe a) 
     340  -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~^       `a' is first bound here 
     341  -- ~~~~~~~~~~~~~~~^                   the same `a' then used here 
     342  = do { sig' <- rnHsSigCps sig 
     343       ; pat' <- rnLPatAndThen mk pat 
    335344       ; return (SigPatIn pat' sig') } 
    336345        
    337346rnPatAndThen mk (LitPat lit)