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

Type reexports explicitly use 'type' namespace #11451

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 ::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m a bit surprised this works. Why do we not need to enable ExplicitNameSpaces when compiling the dummy interface files? It clearly does work I just don’t understand how.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! It's implied by TypeOperators, which IIUC is part of the header for the generated files

header =
[ "{-# LANGUAGE NoDamlSyntax #-}"
, "{-# LANGUAGE NoImplicitPrelude #-}"
, "{-# LANGUAGE NoOverloadedStrings #-}"
, "{-# LANGUAGE TypeOperators #-}"
, "{-# LANGUAGE UndecidableInstances #-}"
, "{-# LANGUAGE AllowAmbiguousTypes #-}"
, "{-# LANGUAGE MagicHash #-}"
, "{-# OPTIONS_GHC -Wno-unused-imports -Wno-missing-methods -Wno-deprecations #-}"
]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah makes sense, thanks for the explanation!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem! 😃

(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
Expand Down
28 changes: 28 additions & 0 deletions compiler/damlc/tests/src/DA/Test/DataDependencies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down