Skip to content

Commit

Permalink
Preserve empty variant constructor in data-deps.
Browse files Browse the repository at this point in the history
This fixes #7207 and adds a regression test. In a
separate PR I'll add a warning for variants with
single argument of unit type and add a changelog
entry.

changelog_begin
changelog_end
  • Loading branch information
sofiafaro-da committed Sep 2, 2020
1 parent abb979a commit 31a694c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ generateSrcFromLf env = noLoc mod

convConDetails :: LF.Type -> Gen (HsConDeclDetails GhcPs)
convConDetails = \case
-- empty variant constructor (see issue #7207)
LF.TUnit ->
pure $ PrefixCon []

-- variant record constructor
LF.TConApp LF.Qualified{..} _
Expand Down
43 changes: 43 additions & 0 deletions compiler/damlc/tests/src/DA/Test/Packaging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
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.
Expand Down

0 comments on commit 31a694c

Please sign in to comment.