-
Notifications
You must be signed in to change notification settings - Fork 205
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -479,6 +479,9 @@ generateSrcFromLf env = noLoc mod | |
|
||
convConDetails :: LF.Type -> Gen (HsConDeclDetails GhcPs) | ||
convConDetails = \case | ||
-- empty variant constructor (see issue #7207) | ||
LF.TUnit -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means that a variant where I explicilty specify a Unit argument will also be decompiled to a Prefix con right? I think that’s perfectly reasonable but probably worth documenting in a comment and perhaps warning on in the preprocessor. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's what we decided on in the issue and I'm preparing the warning in a separate PR. |
||
pure $ PrefixCon [] | ||
|
||
-- variant record constructor | ||
LF.TConApp LF.Qualified{..} _ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1667,6 +1667,49 @@ dataDependencyTests Tools{damlc,repl,validate,davlDar,oldProjDar} = testGroup "D | |
withCurrentDirectory (tmpDir </> "proj") $ | ||
callProcessSilent damlc ["build"] | ||
|
||
, testCaseSteps "Empty variant constructors" $ \step -> withTempDir $ \tmpDir -> do | ||
-- This test checks that variant constructors without argument | ||
-- are preserved. This is a regression test for issue #7207. | ||
step "building project with type definition" | ||
createDirectoryIfMissing True (tmpDir </> "type") | ||
writeFileUTF8 (tmpDir </> "type" </> "daml.yaml") $ unlines | ||
[ "sdk-version: " <> sdkVersion | ||
, "name: type" | ||
, "source: ." | ||
, "version: 0.1.0" | ||
, "dependencies: [daml-prim, daml-stdlib]" | ||
] | ||
writeFileUTF8 (tmpDir </> "type" </> "Foo.daml") $ unlines | ||
[ "module Foo where" | ||
, "data A = B | C Int" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a third case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I generally agree but would feel more comfortable to have a test as long as users can still write it, even though they get warned about it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a test for |
||
] | ||
withCurrentDirectory (tmpDir </> "type") $ | ||
callProcessSilent damlc ["build", "-o", "type.dar"] | ||
|
||
step "building project that uses it via data-dependencies" | ||
createDirectoryIfMissing True (tmpDir </> "proj") | ||
writeFileUTF8 (tmpDir </> "proj" </> "daml.yaml") $ unlines | ||
[ "sdk-version: " <> sdkVersion | ||
, "name: proj" | ||
, "source: ." | ||
, "version: 0.1.0" | ||
, "dependencies: [daml-prim, daml-stdlib]" | ||
, "data-dependencies: " | ||
, " - " <> (tmpDir </> "type" </> "type.dar") | ||
] | ||
writeFileUTF8 (tmpDir </> "proj" </> "Main.daml") $ unlines | ||
[ "module Main where" | ||
, "import Foo" | ||
, "mkA : A" | ||
, "mkA = B" | ||
, "matchA : A -> Int" | ||
, "matchA a =" | ||
, " case a of" | ||
, " B -> 0" | ||
, " C n -> n" | ||
] | ||
withCurrentDirectory (tmpDir </> "proj") $ | ||
callProcessSilent damlc ["build"] | ||
] | ||
|
||
-- | Check that the given file exists in the dar in the given directory. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Empty" is such an overloaded word:
Or "payload" instead of "argument".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but "variant constructor without argument" is such a clumsy phrase, and what else could "empty variant constructor" mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the right answer here is "nullary variant constructor".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like "nullary variant constructor". 👍