diff options
author | Patrick Palka <patrick@parcs.ath.cx> | 2013-04-11 14:00:51 -0400 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2013-04-12 12:21:03 +0100 |
commit | 37be6f06feed7351336bf8301fab93ac7c4d3a12 (patch) | |
tree | 61eb441f03d02df6036787c4a98c00db38d26c09 /compiler | |
parent | 6afa7779b9614aea7130238b31f4864616f9205e (diff) | |
download | haskell-37be6f06feed7351336bf8301fab93ac7c4d3a12.tar.gz |
Fix type variable scoping in nested pattern type signatures (#7827)
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/rename/RnPat.lhs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/compiler/rename/RnPat.lhs b/compiler/rename/RnPat.lhs index a039f36b25..205dde1969 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) |