@@ -529,11 +529,11 @@ equalP x y = inheritLoc x $
529529--
530530-- NOTE: The GHC AST (but not TH) supports declaring multiple record fields
531531-- with the same type. We do not support this here (since we follow TH).
532- recC :: LIdP GhcPs -> [(LIdP GhcPs , LHsType GhcPs )] -> LConDecl GhcPs
532+ recC :: LIdP GhcPs -> [(LIdP GhcPs , LHsType GhcPs , HsSrcBang )] -> LConDecl GhcPs
533533recC = forallRecC [] []
534534
535535-- | Inverse to 'recC'
536- viewRecC :: LConDecl GhcPs -> Maybe (LIdP GhcPs , [(LIdP GhcPs , LHsType GhcPs )])
536+ viewRecC :: LConDecl GhcPs -> Maybe (LIdP GhcPs , [(LIdP GhcPs , LHsType GhcPs , HsSrcBang )])
537537viewRecC
538538 (L _
539539 ConDeclH98 {
@@ -549,14 +549,14 @@ viewRecC
549549 }
550550 ) = (conName ,) <$> mapM viewRecField fields
551551 where
552- viewRecField :: LConDeclField GhcPs -> Maybe (LIdP GhcPs , LHsType GhcPs )
552+ viewRecField :: LConDeclField GhcPs -> Maybe (LIdP GhcPs , LHsType GhcPs , HsSrcBang )
553553 viewRecField
554554 (L _
555555 ConDeclField {
556556 cd_fld_names = [L _ name]
557557 , cd_fld_type = ty
558558 }
559- ) = Just $ (viewFieldOcc name, ty)
559+ ) = Just (viewFieldOcc name, getBangType ty, getBangStrictness ty)
560560 viewRecField _otherwise = Nothing
561561
562562 viewFieldOcc :: FieldOcc GhcPs -> LIdP GhcPs
@@ -566,7 +566,7 @@ viewRecC
566566#endif
567567viewRecC _otherwise = Nothing
568568
569- pattern RecC :: LIdP GhcPs -> [(LIdP GhcPs , LHsType GhcPs )] -> LConDecl GhcPs
569+ pattern RecC :: LIdP GhcPs -> [(LIdP GhcPs , LHsType GhcPs , HsSrcBang )] -> LConDecl GhcPs
570570pattern RecC conName args <- (viewRecC -> Just (conName, args))
571571 where
572572 RecC = recC
@@ -577,26 +577,34 @@ forallRecC ::
577577 [LIdP GhcPs ] -- ^ @forallC@ argument: bound type variables
578578 -> [LHsType GhcPs ] -- ^ @forallC@ argument: context
579579 -> LIdP GhcPs -- ^ @recC@ argument: record constructor name
580- -> [(LIdP GhcPs , LHsType GhcPs )] -- ^ @recC@ argument: record fields
580+ -> [(LIdP GhcPs , LHsType GhcPs , HsSrcBang )] -- ^ @recC@ argument: record fields
581581 -> LConDecl GhcPs
582582forallRecC vars ctxt conName args = inheritLoc conName $ ConDeclH98 {
583583 con_ext = defExt
584584 , con_name = conName
585585 , con_forall = inheritLoc conName True
586586 , con_ex_tvs = map (setDefaultSpecificity . mkBndr) vars
587587 , con_mb_cxt = Just (inheritLoc conName ctxt)
588- , con_args = RecCon (inheritLoc conName $ map ( uncurry mkRecField) args)
588+ , con_args = RecCon (inheritLoc conName $ map mkRecField args)
589589 , con_doc = Nothing
590590 }
591591 where
592592 mkBndr :: LIdP GhcPs -> LHsTyVarBndr GhcPs
593593 mkBndr name = inheritLoc name $ userTyVar name
594594
595- mkRecField :: LIdP GhcPs -> LHsType GhcPs -> LConDeclField GhcPs
596- mkRecField name ty = inheritLoc name $ ConDeclField {
595+ optionalBang :: HsSrcBang -> LHsType GhcPs -> LHsType GhcPs
596+ optionalBang bang = noLocA . HsBangTy defExt
597+ #if __GLASGOW_HASKELL__ >= 912
598+ (case bang of HsSrcBang _ b -> b)
599+ #else
600+ bang
601+ #endif
602+
603+ mkRecField :: (LIdP GhcPs , LHsType GhcPs , HsSrcBang ) -> LConDeclField GhcPs
604+ mkRecField (name, ty, bang) = inheritLoc name $ ConDeclField {
597605 cd_fld_ext = defExt
598606 , cd_fld_names = [inheritLoc name $ mkFieldOcc name]
599- , cd_fld_type = ty
607+ , cd_fld_type = optionalBang bang ty
600608 , cd_fld_doc = Nothing
601609 }
602610
0 commit comments