From 17777781116e954014b028e393eed54ff7d17fb3 Mon Sep 17 00:00:00 2001
From: Shayne Fletcher
Date: Fri, 24 Jan 2020 15:52:00 -0500
Subject: [PATCH] Fix missing module refs issue
changelog_begin
changelog_end
---
language-support/ts/codegen/src/TsCodeGenMain.hs | 3 ++-
language-support/ts/codegen/tests/daml/Main.daml | 14 ++++++++++++++
language-support/ts/codegen/tests/daml/T.daml | 9 +++++++++
3 files changed, 25 insertions(+), 1 deletion(-)
create mode 100644 language-support/ts/codegen/tests/daml/T.daml
diff --git a/language-support/ts/codegen/src/TsCodeGenMain.hs b/language-support/ts/codegen/src/TsCodeGenMain.hs
index f5f7e7f1badd..fa805e300940 100644
--- a/language-support/ts/codegen/src/TsCodeGenMain.hs
+++ b/language-support/ts/codegen/src/TsCodeGenMain.hs
@@ -206,13 +206,14 @@ genDefDataType curPkgId conName mod tpls def =
Nothing -> ((makeType typeDesc, makeSer serDesc), Set.unions fieldRefs)
Just tpl ->
let (chcs, argRefs) = unzip
- [((unChoiceName (chcName chc), t, rtyp, rser), argRefs)
+ [((unChoiceName (chcName chc), t, rtyp, rser), Set.union argRefs retRefs)
| chc <- NM.toList (tplChoices tpl)
, let tLf = snd (chcArgBinder chc)
, let rLf = chcReturnType chc
, let (t, _) = genType (moduleName mod) tLf
, let (rtyp, rser) = genType (moduleName mod) rLf
, let argRefs = Set.setOf typeModuleRef tLf
+ , let retRefs = Set.setOf typeModuleRef rLf
]
(keyTypeTs, keySer) = case tplKey tpl of
Nothing -> ("undefined", "() => jtv.constant(undefined)")
diff --git a/language-support/ts/codegen/tests/daml/Main.daml b/language-support/ts/codegen/tests/daml/Main.daml
index 5de42f716eca..db1c5b48b652 100644
--- a/language-support/ts/codegen/tests/daml/Main.daml
+++ b/language-support/ts/codegen/tests/daml/Main.daml
@@ -6,6 +6,7 @@ module Main where
import DA.TextMap
import Lib.Mod
+import T
template AllTypes with
unit: ()
@@ -90,3 +91,16 @@ data Quux =
Corge { x: Int, y: Text }
| Grault { z: Bool }
deriving (Show, Eq)
+
+-- This template is interesting in that the 'T' it mentions is
+-- external to this module and only mentioned as a choice return
+-- type. Thus, for the resulting Main.ts to compile, we are testing
+-- that we have correctly generated import directives for this case.
+template U with
+ party: Party
+ where
+ signatory party
+ controller party can
+ C: ContractId T with
+ do
+ create T with party
diff --git a/language-support/ts/codegen/tests/daml/T.daml b/language-support/ts/codegen/tests/daml/T.daml
new file mode 100644
index 000000000000..92ec91fa8c75
--- /dev/null
+++ b/language-support/ts/codegen/tests/daml/T.daml
@@ -0,0 +1,9 @@
+-- Copyright (c) 2020 The DAML Authors. All rights reserved.
+-- SPDX-License-Identifier: Apache-2.0
+daml 1.2
+-- See 'template U' in Main.daml for why this is here.
+module T where
+template T with
+ party: Party
+ where
+ signatory party