From 31a694c978115df5d7f60920803625162cbf67f4 Mon Sep 17 00:00:00 2001 From: Sofia Faro Date: Wed, 2 Sep 2020 12:40:33 +0100 Subject: [PATCH] Preserve empty variant constructor in data-deps. 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 --- .../src/DA/Daml/Compiler/DataDependencies.hs | 3 ++ compiler/damlc/tests/src/DA/Test/Packaging.hs | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/compiler/damlc/daml-compiler/src/DA/Daml/Compiler/DataDependencies.hs b/compiler/damlc/daml-compiler/src/DA/Daml/Compiler/DataDependencies.hs index ced5b5408c26..2fd4db06b04c 100644 --- a/compiler/damlc/daml-compiler/src/DA/Daml/Compiler/DataDependencies.hs +++ b/compiler/damlc/daml-compiler/src/DA/Daml/Compiler/DataDependencies.hs @@ -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{..} _ diff --git a/compiler/damlc/tests/src/DA/Test/Packaging.hs b/compiler/damlc/tests/src/DA/Test/Packaging.hs index f256cf8bb858..c4b0449639b1 100644 --- a/compiler/damlc/tests/src/DA/Test/Packaging.hs +++ b/compiler/damlc/tests/src/DA/Test/Packaging.hs @@ -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.