In a pattern binding, a type sig in the pattern cannot bind a type variable
authorsimonpj@microsoft.com <unknown>
Sat, 27 Oct 2007 15:33:30 +0000 (15:33 +0000)
committersimonpj@microsoft.com <unknown>
Sat, 27 Oct 2007 15:33:30 +0000 (15:33 +0000)
In a pattern binding with a pattern type signature, such as

(Just (x::a)) = e

the pattern type signature cannot bind type variables.  Hence
'a' must be in scope already for the above example to be legal.

This has been the situation for some time, but Dan changed it when
adding view patterns.  This one-line change restores the old behaviour.

compiler/rename/RnPat.lhs

index 56e84d7..c3dc8af 100644 (file)
@@ -106,8 +106,9 @@ applyNameMaker (NM f) x = f x
 --  (2) whether the scope of the names is entirely given in a continuation\r
 --      (e.g., in a case or lambda, but not in a let or at the top-level,\r
 --       because of the way mutually recursive bindings are handled)\r
---  (3) whether the type signatures can bind variables\r
---      (for unpacking existential type vars in data constructors)\r
+--  (3) whether the a type signature in the pattern can bind \r
+--     lexically-scoped type variables (for unpacking existential \r
+--     type vars in data constructors)\r
 --  (4) whether we do duplicate and unused variable checking\r
 --  (5) whether there are fixity declarations associated with the names\r
 --      bound by the patterns that need to be brought into scope with them.\r
@@ -117,7 +118,7 @@ applyNameMaker (NM f) x = f x
 \r
 -- entry point 1:\r
 -- binds local names; the scope of the bindings is entirely in the thing_inside\r
---   allows type sigs to bind vars\r
+--   allows type sigs to bind type vars\r
 --   local namemaker\r
 --   unused and duplicate checking\r
 --   no fixities\r
@@ -164,7 +165,8 @@ rnPatsAndThen_LocalRightwards ctxt pats thing_inside =
 \r
 -- entry point 2:\r
 -- binds local names; in a recursive scope that involves other bound vars\r
---   allows type sigs to bind vars\r
+--     e.g let { (x, Just y) = e1; ... } in ...\r
+--   does NOT allows type sig to bind type vars\r
 --   local namemaker\r
 --   no unused and duplicate checking\r
 --   fixities might be coming in\r
@@ -177,7 +179,6 @@ rnPat_LocalRec :: UniqFM (Located Fixity) -- mini fixity env for the names we're
                        FreeVars)\r
 \r
 rnPat_LocalRec fix_env pat = \r
-    bindPatSigTyVarsFV (collectSigTysFromPats [pat]) $ \r
     rnLPatsAndThen localNameMaker fix_env [pat]               $ \ ([pat'], pat_fvs) ->\r
         return (pat', pat_fvs)\r
 \r