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

Add a guard when exercising by interface. #11836

Merged
merged 8 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
rebase and fix parser
  • Loading branch information
sofiafaro-da committed Nov 24, 2021
commit aeb7f8a5736063bb40a14dabb3b18b0443716273
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ private[lf] final class Compiler(
t.GuardedChoiceDefRef(interfaceId, choiceId)(
s.SEValue(contractId),
s.SEValue(argument),
s.SBGuardTemplateId(templateId)(s.SEValue(contractId)),
SBGuardTemplateId(templateId)(s.SEValue(contractId)),
)
case Command.ExerciseInterface(interfaceId, contractId, choiceId, argument) =>
t.ChoiceDefRef(interfaceId, choiceId)(s.SEValue(contractId), s.SEValue(argument))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1172,14 +1172,17 @@ private[lf] object SBuiltin {

final case class SBGuardTemplateId(
templateId: TypeConName
) extends SBuiltinPure(2) {
override private[speedy] def executePure(args: util.ArrayList[SValue]): SBool = {
) extends SBuiltin(2) {
override private[speedy] def execute(
args: util.ArrayList[SValue],
machine: Machine,
): Unit = {
val coid = getSContractId(args, 0)
val record = getSRecord(args, 1)
if (record.id != templateId)
throw IE.WronglyTypedContract(coid, templateId, record.id)
machine.ctrl = SEDamlException(IE.WronglyTypedContract(coid, templateId, record.id))
else
SBool(true)
machine.returnValue = SBool(true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ private[parser] class ExprParser[P](parserParameters: ParserParameters[P]) {
private lazy val updateExerciseInterface =
Id("exercise_by_interface") ~! `@` ~> fullIdentifier ~ id ~ expr0 ~ expr0 ^^ {
case iface ~ choice ~ cid ~ arg =>
UpdateExerciseInterface(iface, choice, cid, arg)
UpdateExerciseInterface(iface, choice, cid, arg, None)
// TODO https://github.com/digital-asset/daml/issues/11703
// Implement choice guard argument.
}

private lazy val updateExerciseByKey =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ class ParsersSpec extends AnyWordSpec with ScalaCheckPropertyChecks with Matcher
"exercise @Mod:T Choice cid arg" ->
UpdateExercise(T.tycon, n"Choice", e"cid", e"arg"),
"exercise_by_interface @Mod:I Choice cid arg" ->
UpdateExerciseInterface(I.tycon, n"Choice", e"cid", e"arg"),
UpdateExerciseInterface(I.tycon, n"Choice", e"cid", e"arg", None),
"exercise_by_key @Mod:T Choice key arg" ->
UpdateExerciseByKey(T.tycon, n"Choice", e"key", e"arg"),
"fetch_by_key @Mod:T e" ->
Expand Down Expand Up @@ -569,7 +569,7 @@ class ParsersSpec extends AnyWordSpec with ScalaCheckPropertyChecks with Matcher
choice Feed;
choice Rest;
};
implements '-pkgId-':Mod2:Referenceable {
implements '-pkgId-':Mod2:Referenceable {
method uuid = "123e4567-e89b-12d3-a456-426614174000";
};
key @Party (Mod:Person {name} this) (\ (p: Party) -> p);
Expand Down Expand Up @@ -756,7 +756,7 @@ class ParsersSpec extends AnyWordSpec with ScalaCheckPropertyChecks with Matcher

val p = """
module Mod {

interface (this: Person) = {
precondition False;
method asParty: Party;
Expand All @@ -770,7 +770,7 @@ class ParsersSpec extends AnyWordSpec with ScalaCheckPropertyChecks with Matcher
to upure @Int64 i;
} ;
}

"""

val interface =
Expand Down