Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve empty variant constructor in data-deps. #7303

Merged
merged 3 commits into from
Sep 2, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add special case for single constructor variants
  • Loading branch information
sofiafaro-da committed Sep 2, 2020
commit 1cca2aeec885f8af9e377299b984af1ff1a8fad8
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,9 @@ generateSrcFromLf env = noLoc mod
fields' <- mapM (uncurry (mkConDeclField env)) fields
pure [ mkConDecl occName (RecCon (noLoc fields')) ]
LF.DataVariant cons -> do
let hasExactlyOneConstructor = length cons == 1
sequence
[ mkConDecl (occNameFor conName) <$> convConDetails ty
[ mkConDecl (occNameFor conName) <$> convConDetails hasExactlyOneConstructor ty
| (conName, ty) <- cons
]
LF.DataEnum cons -> do
Expand All @@ -477,10 +478,14 @@ generateSrcFromLf env = noLoc mod
, con_args = details
}

convConDetails :: LF.Type -> Gen (HsConDeclDetails GhcPs)
convConDetails = \case
-- empty variant constructor (see issue #7207)
LF.TUnit ->
convConDetails :: Bool -> LF.Type -> Gen (HsConDeclDetails GhcPs)
convConDetails hasExactlyOneConstructor = \case
-- nullary variant constructor (see issue #7207)
--
-- We translate a variant constructor `C ()` to `C` in DAML. But
-- if it's the only constructor, we leave it as `C ()` to distinguish
-- it from an enum type.
LF.TUnit | not hasExactlyOneConstructor ->
pure $ PrefixCon []

-- variant record constructor
Expand Down