From 37be6f06feed7351336bf8301fab93ac7c4d3a12 Mon Sep 17 00:00:00 2001 From: Patrick Palka 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 a039f36b2574..205dde196993 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)