-tcPat sig_fn (VarPatIn name) pat_ty
- = tcVarPat sig_fn name pat_ty `thenTc` \ bndr_id ->
- returnTc (VarPat (TcId bndr_id), emptyLIE, emptyBag, unitBag (name, bndr_id), emptyLIE)
-
-tcPat sig_fn (LazyPatIn pat) pat_ty
- = tcPat sig_fn pat pat_ty `thenTc` \ (pat', lie_req, tvs, ids, lie_avail) ->
- returnTc (LazyPat pat', lie_req, tvs, ids, lie_avail)
-
-tcPat sig_fn pat_in@(AsPatIn name pat) pat_ty
- = tcVarPat sig_fn name pat_ty `thenTc` \ bndr_id ->
- tcPat sig_fn pat pat_ty `thenTc` \ (pat', lie_req, tvs, ids, lie_avail) ->
- tcAddErrCtxt (patCtxt pat_in) $
- returnTc (AsPat (TcId bndr_id) pat', lie_req,
- tvs, (name, bndr_id) `consBag` ids,
- lie_avail)
-
-tcPat sig_fn WildPatIn pat_ty
- = returnTc (WildPat pat_ty, emptyLIE, emptyBag, emptyBag, emptyLIE)
-
-tcPat sig_fn (NegPatIn pat) pat_ty
- = tcPat sig_fn (negate_lit pat) pat_ty
- where
- negate_lit (LitPatIn (HsInt i)) = LitPatIn (HsInt (-i))
- negate_lit (LitPatIn (HsFrac f)) = LitPatIn (HsFrac (-f))
- negate_lit _ = panic "TcPat:negate_pat"
-
-tcPat sig_fn (ParPatIn parend_pat) pat_ty
- = tcPat sig_fn parend_pat pat_ty
+tc_pat tc_bndr pat@(TypePat ty) pat_ty
+ = failWithTc (badTypePat pat)
+
+tc_pat tc_bndr (VarPat name) pat_ty
+ = tc_bndr name pat_ty `thenM` \ (co_fn, bndr_id) ->
+ returnM (co_fn <$> VarPat bndr_id,
+ emptyBag, unitBag (name, bndr_id), [])
+
+tc_pat tc_bndr (LazyPat pat) pat_ty
+ = tcPat tc_bndr pat pat_ty `thenM` \ (pat', tvs, ids, lie_avail) ->
+ returnM (LazyPat pat', tvs, ids, lie_avail)
+
+tc_pat tc_bndr pat_in@(AsPat (L nm_loc name) pat) pat_ty
+ = addSrcSpan nm_loc (tc_bndr name pat_ty) `thenM` \ (co_fn, bndr_id) ->
+ tcPat tc_bndr pat (Check (idType bndr_id)) `thenM` \ (pat', tvs, ids, lie_avail) ->
+ -- NB: if we have:
+ -- \ (y@(x::forall a. a->a)) = e
+ -- we'll fail. The as-pattern infers a monotype for 'y', which then
+ -- fails to unify with the polymorphic type for 'x'. This could be
+ -- fixed, but only with a bit more work.
+ returnM (co_fn <$> (AsPat (L nm_loc bndr_id) pat'),
+ tvs, (name, bndr_id) `consBag` ids, lie_avail)
+
+tc_pat tc_bndr (WildPat _) pat_ty
+ = zapExpectedType pat_ty argTypeKind `thenM` \ pat_ty' ->
+ -- We might have an incoming 'hole' type variable; no annotation
+ -- so zap it to a type. Rather like tcMonoPatBndr.
+ -- Note argTypeKind, so that
+ -- f _ = 3
+ -- is rejected when f applied to an unboxed tuple
+ -- However, this means that
+ -- (case g x of _ -> ...)
+ -- is rejected g returns an unboxed tuple, which is perhpas
+ -- annoying. I suppose we could pass the context into tc_pat...
+ returnM (WildPat pat_ty', emptyBag, emptyBag, [])
+
+tc_pat tc_bndr (ParPat parend_pat) pat_ty
+-- Leave the parens in, so that warnings from the
+-- desugarer have parens in them
+ = tcPat tc_bndr parend_pat pat_ty `thenM` \ (pat', tvs, ids, lie_avail) ->
+ returnM (ParPat pat', tvs, ids, lie_avail)
+
+tc_pat tc_bndr pat_in@(SigPatIn pat sig) pat_ty
+ = addErrCtxt (patCtxt pat_in) $
+ tcHsSigType PatSigCtxt sig `thenM` \ sig_ty ->
+ tcSubPat sig_ty pat_ty `thenM` \ co_fn ->
+ tcPat tc_bndr pat (Check sig_ty) `thenM` \ (pat', tvs, ids, lie_avail) ->
+ returnM (co_fn <$> unLoc pat', tvs, ids, lie_avail)