From eb318756ff62879c6a9efabf5e2145c241c1a975 Mon Sep 17 00:00:00 2001 From: Francesco Mazzoli Date: Mon, 8 Apr 2019 11:59:49 +0200 Subject: [PATCH] decode key expressions in scala correctly. fixes #177 (#214) * decode key expressions in scala correctly. fixes #177 replaced a `foldRight` with a `foldLeft`, projections were decoded backwards. * remove ContractKeysSimple -- superseded by ContractKeys --- .../daml-ghc/tests/ContractKeys.daml | 2 - .../daml-ghc/tests/ContractKeysSimple.daml | 51 ------------------- .../daml/lf/lfpackage/DecodeV1.scala | 4 +- 3 files changed, 2 insertions(+), 55 deletions(-) delete mode 100644 daml-foundations/daml-ghc/tests/ContractKeysSimple.daml diff --git a/daml-foundations/daml-ghc/tests/ContractKeys.daml b/daml-foundations/daml-ghc/tests/ContractKeys.daml index 2366392886..754a73816f 100644 --- a/daml-foundations/daml-ghc/tests/ContractKeys.daml +++ b/daml-foundations/daml-ghc/tests/ContractKeys.daml @@ -1,9 +1,7 @@ -- Check that the compiler bits of contract keys work. --- @TODO (#177): Fix the engine such that this test passes. Remove `ContractKeysSimple.daml` when it does. -- @IGNORE-LF 1.0 -- @IGNORE-LF 1.1 -- @IGNORE-LF 1.2 --- @ERROR CRASH: RecProj on non-record daml 1.2 module ContractKeys where diff --git a/daml-foundations/daml-ghc/tests/ContractKeysSimple.daml b/daml-foundations/daml-ghc/tests/ContractKeysSimple.daml deleted file mode 100644 index 9c836aeef7..0000000000 --- a/daml-foundations/daml-ghc/tests/ContractKeysSimple.daml +++ /dev/null @@ -1,51 +0,0 @@ --- Check that the compiler bits of contract keys work. --- @TODO (#177): Remove this test when #177 has been fixed. --- @IGNORE-LF 1.0 --- @IGNORE-LF 1.1 --- @IGNORE-LF 1.2 -daml 1.2 -module ContractKeysSimple where - -template AccountInvitation with - account : Account - where - signatory account.bank - - controller account.accountHolder can - Accept : ContractId Account - do create account - -template Account with - bank : Party - accountHolder : Party - accountCode : Text - accountNumber : Int - where - signatory [bank, accountHolder] - -instance Key Account (Party, Text, Int) where - key acc = (acc.bank, acc.accountCode, acc.accountNumber) - keyMaintainers Proxy (bank, _, _) = [bank] - -test = scenario do - bank <- getParty "Bank" - alice <- getParty "Alice" - let account = Account with - bank - accountHolder = alice - accountCode = "CH" - accountNumber = 123 - let accountKey = (bank, "CH", 123) - invitationCid <- submit bank do - create AccountInvitation with account - accountCid <- submit alice do - exercise invitationCid Accept - - accountCid' <- submit bank do - lookupByKey accountKey - assert $ accountCid' == Some accountCid - - (accountCid', account') <- submit bank do - fetchByKey accountKey - assert $ accountCid' == accountCid - assert $ account' == account diff --git a/daml-lf/lfpackage/src/main/scala/com/digitalasset/daml/lf/lfpackage/DecodeV1.scala b/daml-lf/lfpackage/src/main/scala/com/digitalasset/daml/lf/lfpackage/DecodeV1.scala index d110bf9a08..0154b3cd77 100644 --- a/daml-lf/lfpackage/src/main/scala/com/digitalasset/daml/lf/lfpackage/DecodeV1.scala +++ b/daml-lf/lfpackage/src/main/scala/com/digitalasset/daml/lf/lfpackage/DecodeV1.scala @@ -164,8 +164,8 @@ private[lf] class DecodeV1(minor: LanguageMinorVersion) extends Decode.OfPackage case PLF.KeyExpr.SumCase.PROJECTIONS => val lfProjs = expr.getProjections.getProjectionsList.asScala - (lfProjs :\ (EVar(tplVar): Expr)) { - case (lfProj, acc) => + lfProjs.foldLeft(EVar(tplVar): Expr) { + case (acc, lfProj) => ERecProj(decodeTypeConApp(lfProj.getTycon), lfProj.getField, acc) }