[commit: ghc] master: Fix type variable scoping in nested pattern type signatures (#7827) (37be6f0)

Simon Peyton Jones simonpj at microsoft.com
Fri Apr 12 14:27:08 CEST 2013


Repository : http://darcs.haskell.org/ghc.git/

On branch  : master

https://github.com/ghc/ghc/commit/37be6f06feed7351336bf8301fab93ac7c4d3a12

>---------------------------------------------------------------

commit 37be6f06feed7351336bf8301fab93ac7c4d3a12
Author: Patrick Palka <patrick at parcs.ath.cx>
Date:   Thu Apr 11 14:00:51 2013 -0400

    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..205dde1 100644
--- a/compiler/rename/RnPat.lhs
+++ b/compiler/rename/RnPat.lhs
@@ -330,8 +330,17 @@ rnPatAndThen mk (VarPat rdr)  = do { loc <- liftCps getSrcSpanM
      -- (e.g. in the pattern (x, x -> y) x needs to be bound in the rhs of the tuple)
                                      
 rnPatAndThen mk (SigPatIn pat sig)
-  = do { pat' <- rnLPatAndThen mk pat
-       ; sig' <- rnHsSigCps sig
+  -- When renaming a pattern type signature (e.g. f (a :: T) = ...), it is
+  -- important to rename its type signature _before_ renaming the rest of the
+  -- pattern, so that type variables are first bound by the _outermost_ pattern
+  -- type signature they occur in. This keeps the type checker happy when
+  -- pattern type signatures happen to be nested (#7827)
+  --
+  -- f ((Just (x :: a) :: Maybe a)
+  -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~^       `a' is first bound here
+  -- ~~~~~~~~~~~~~~~^                   the same `a' then used here
+  = do { sig' <- rnHsSigCps sig
+       ; pat' <- rnLPatAndThen mk pat
        ; return (SigPatIn pat' sig') }
        
 rnPatAndThen mk (LitPat lit)





More information about the ghc-commits mailing list