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
This commit is contained in:
Francesco Mazzoli 2019-04-08 11:59:49 +02:00 committed by GitHub
parent 8b9f2e5860
commit eb318756ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 55 deletions

View File

@ -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

View File

@ -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

View File

@ -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)
}