- = isProductTyCon (dataConTyCon con)
- && all go (hsConArgs details)
-
- go1 (LitPat _) = False
- go1 (NPat _ _ _ _) = False
- go1 (NPlusKPat _ _ _ _) = False
-
- go1 (TypePat _) = panic "isIrrefutableHsPat: type pattern"
- go1 (DictPat _ _) = panic "isIrrefutableHsPat: type pattern"
+ = isJust (tyConSingleDataCon_maybe (dataConTyCon con))
+ -- NB: tyConSingleDataCon_maybe, *not* isProductTyCon, because
+ -- the latter is false of existentials. See Trac #4439
+ && all go (hsConPatArgs details)
+
+ go1 (LitPat {}) = False
+ go1 (NPat {}) = False
+ go1 (NPlusKPat {}) = False
+
+ go1 (QuasiQuotePat {}) = urk pat -- Gotten rid of by renamer, before
+ -- isIrrefutablePat is called
+
+ urk pat = pprPanic "isIrrefutableHsPat:" (ppr pat)
+
+hsPatNeedsParens :: Pat a -> Bool
+hsPatNeedsParens (WildPat {}) = False
+hsPatNeedsParens (VarPat {}) = False
+hsPatNeedsParens (LazyPat {}) = False
+hsPatNeedsParens (BangPat {}) = False
+hsPatNeedsParens (CoPat {}) = True
+hsPatNeedsParens (ParPat {}) = False
+hsPatNeedsParens (AsPat {}) = False
+hsPatNeedsParens (ViewPat {}) = True
+hsPatNeedsParens (SigPatIn {}) = True
+hsPatNeedsParens (SigPatOut {}) = True
+hsPatNeedsParens (TuplePat {}) = False
+hsPatNeedsParens (ListPat {}) = False
+hsPatNeedsParens (PArrPat {}) = False
+hsPatNeedsParens (ConPatIn _ ds) = conPatNeedsParens ds
+hsPatNeedsParens (ConPatOut {}) = True
+hsPatNeedsParens (LitPat {}) = False
+hsPatNeedsParens (NPat {}) = False
+hsPatNeedsParens (NPlusKPat {}) = True
+hsPatNeedsParens (QuasiQuotePat {}) = True
+
+conPatNeedsParens :: HsConDetails a b -> Bool
+conPatNeedsParens (PrefixCon args) = not (null args)
+conPatNeedsParens (InfixCon {}) = False
+conPatNeedsParens (RecCon {}) = False