From 8323e412c985c053d7db312a4cf9dea505ae51e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20Ackerman?= <6054733+akrmn@users.noreply.github.com> Date: Thu, 28 Oct 2021 14:15:01 +0200 Subject: [PATCH] Type reexports explicitly use 'type' namespace This ensures that type operators are reexported correctly. Closes #11447 changelog_begin changelog_end --- .../src/DA/Daml/Compiler/DataDependencies.hs | 13 +++++---- .../tests/src/DA/Test/DataDependencies.hs | 28 +++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) 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 6fefe3ac7c2c..f796e8f12963 100644 --- a/compiler/damlc/daml-compiler/src/DA/Daml/Compiler/DataDependencies.hs +++ b/compiler/damlc/daml-compiler/src/DA/Daml/Compiler/DataDependencies.hs @@ -336,16 +336,19 @@ generateSrcFromLf env = noLoc mod mkLIE = fmap noLoc . \case LFC.ExportInfoVal name -> IEVar NoExt - <$> mkWrappedRdrName name + <$> mkWrappedRdrName IEName name LFC.ExportInfoTC name pieces fields -> IEThingWith NoExt - <$> mkWrappedRdrName name + <$> mkWrappedRdrName IEType name <*> pure NoIEWildcard - <*> mapM mkWrappedRdrName pieces + <*> mapM (mkWrappedRdrName IEName) pieces <*> mapM mkFieldLblRdrName fields - mkWrappedRdrName :: LFC.QualName -> Gen (LIEWrappedName RdrName) - mkWrappedRdrName = fmap (noLoc . IEName . noLoc) . mkRdrName + mkWrappedRdrName :: + (Located RdrName -> IEWrappedName RdrName) + -> LFC.QualName + -> Gen (LIEWrappedName RdrName) + mkWrappedRdrName f = fmap (noLoc . f . noLoc) . mkRdrName mkRdrName :: LFC.QualName -> Gen RdrName mkRdrName (LFC.QualName q) = do diff --git a/compiler/damlc/tests/src/DA/Test/DataDependencies.hs b/compiler/damlc/tests/src/DA/Test/DataDependencies.hs index d3e679c1c284..86ed49950cfe 100644 --- a/compiler/damlc/tests/src/DA/Test/DataDependencies.hs +++ b/compiler/damlc/tests/src/DA/Test/DataDependencies.hs @@ -1381,6 +1381,34 @@ tests Tools{damlc,repl,validate,davlDar,oldProjDar} = testGroup "Data Dependenci ] ] + , dataDependenciesTest "Using reexported type operators" + -- This test checks that we reconstruct reexported type operators properly. + [ + (,) "Base.daml" + [ "{-# LANGUAGE TypeOperators #-}" + , "module Base (type (&) (..), type (+)) where" + , "data a & b = X ()" + , "type a + b = a & b" + ] + , (,) "Wrapper.daml" + [ "module Wrapper (module Base) where" + , "import Base" + ] + ] + [ (,) "Main.daml" + [ "{-# LANGUAGE TypeOperators #-}" + , "module Main where" + , "import Wrapper" + , "ampersand: Bool & Int" + , "ampersand = X ()" + , "plus: Int + Bool" + , "plus = X ()" + -- If reexported type operators were not imported correctly, + -- we'd get "missing type" or "expecting type constructor + -- but found a variable" errors from GHC. + ] + ] + , testCaseSteps "User-defined exceptions" $ \step -> withTempDir $ \tmpDir -> do step "building project to be imported via data-dependencies" createDirectoryIfMissing True (tmpDir "lib")