diff --git a/daml-lf/encoder/src/main/scala/com/digitalasset/daml/lf/archive/testing/EncodeV1.scala b/daml-lf/encoder/src/main/scala/com/digitalasset/daml/lf/archive/testing/EncodeV1.scala index 1a595f11ab06..1189f9ef8021 100644 --- a/daml-lf/encoder/src/main/scala/com/digitalasset/daml/lf/archive/testing/EncodeV1.scala +++ b/daml-lf/encoder/src/main/scala/com/digitalasset/daml/lf/archive/testing/EncodeV1.scala @@ -637,6 +637,14 @@ private[daml] class EncodeV1(minor: LV.Minor) { .setExceptionType(excTy) .setExceptionExpr(exc) ) + case EToAnyException(ty, body) => + assertSince(LV.Features.exceptions, "Expr.ToAnyException") + builder.setToAnyException(PLF.Expr.ToAnyException.newBuilder().setType(ty).setExpr(body)) + case EFromAnyException(ty, body) => + assertSince(LV.Features.exceptions, "Expr.FromAnyException") + builder.setFromAnyException( + PLF.Expr.FromAnyException.newBuilder().setType(ty).setExpr(body) + ) case EExperimental(name, ty) => assertSince(LV.v1_dev, "Expr.experimental") builder.setExperimental(PLF.Expr.Experimental.newBuilder().setName(name).setType(ty)) diff --git a/daml-lf/encoder/src/test/lf/Builtin_1.13_1.dev_.lf b/daml-lf/encoder/src/test/lf/BigNumeric_1.13_1.dev_.lf similarity index 76% rename from daml-lf/encoder/src/test/lf/Builtin_1.13_1.dev_.lf rename to daml-lf/encoder/src/test/lf/BigNumeric_1.13_1.dev_.lf index 2ed4c77a8988..db38875e65e0 100644 --- a/daml-lf/encoder/src/test/lf/Builtin_1.13_1.dev_.lf +++ b/daml-lf/encoder/src/test/lf/BigNumeric_1.13_1.dev_.lf @@ -1,18 +1,7 @@ // Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -module BuiltinMod { - - val equal: forall (a: *). a -> a -> Bool = - EQUAL; - val less_eq: forall (a: *). a -> a -> Bool = - LESS_EQ; - val less: forall (a: *). a -> a -> Bool = - LESS; - val greater_eq: forall (a: *). a -> a -> Bool = - GREATER_EQ; - val greater: forall (a: *). a -> a -> Bool = - GREATER; +module BigNumericMod { val scaleBigNumeric: BigNumeric -> Int64 = SCALE_BIGNUMERIC; diff --git a/daml-lf/encoder/src/test/lf/Builtin_1.11_1.12.lf b/daml-lf/encoder/src/test/lf/Builtin_1.11_1.12_1.13_1.dev_.lf similarity index 100% rename from daml-lf/encoder/src/test/lf/Builtin_1.11_1.12.lf rename to daml-lf/encoder/src/test/lf/Builtin_1.11_1.12_1.13_1.dev_.lf diff --git a/daml-lf/encoder/src/test/lf/Exception_1.dev_.lf b/daml-lf/encoder/src/test/lf/Exception_1.dev_.lf new file mode 100644 index 000000000000..da16a496e836 --- /dev/null +++ b/daml-lf/encoder/src/test/lf/Exception_1.dev_.lf @@ -0,0 +1,27 @@ +// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +module ExceptionMod { + + record @serializable Exception = { message: Text } ; + exception Exception = { + message \(e: ExceptionMod:Exception) -> + ExceptionMod:Exception {message} e + }; + + val anException: ExceptionMod:Exception = + ExceptionMod:Exception {message = "oops"}; + + val throwAndCatch : Update Int64 = + try @Int64 (upure @Int64 (throw @Int64 @ExceptionMod:Exception ExceptionMod:anException)) + catch e -> Some @(Update Int64) (upure @Int64 77); + + val anAnyException: AnyException = + to_any_exception @ExceptionMod:Exception ExceptionMod:anException; + + val anUnwrappedAnyException: Option ExceptionMod:Exception = + from_any_exception @ExceptionMod:Exception ExceptionMod:anAnyException; + + val aMessage: Text = ANY_EXCEPTION_MESSAGE ExceptionMod:anAnyException; + +} diff --git a/daml-lf/encoder/src/test/scala/com/digitalasset/daml/lf/archive/testing/DamlLfEncoderTest.scala b/daml-lf/encoder/src/test/scala/com/digitalasset/daml/lf/archive/testing/DamlLfEncoderTest.scala index 92c7a1e9e51b..13088ae905cd 100644 --- a/daml-lf/encoder/src/test/scala/com/digitalasset/daml/lf/archive/testing/DamlLfEncoderTest.scala +++ b/daml-lf/encoder/src/test/scala/com/digitalasset/daml/lf/archive/testing/DamlLfEncoderTest.scala @@ -48,7 +48,8 @@ class DamlLfEncoderTest val modules_1_7 = modules_1_6 + "NumericMod" + "AnyMod" val modules_1_8 = modules_1_7 + "SynonymMod" val modules_1_11 = modules_1_8 + "GenMapMod" - val modules_1_dev = modules_1_11 + val modules_1_13 = modules_1_11 + "BigNumericMod" + val modules_1_dev = modules_1_13 + "ExceptionMod" val versions = Table( "versions" -> "modules", @@ -56,6 +57,7 @@ class DamlLfEncoderTest "1.7" -> modules_1_7, "1.8" -> modules_1_8, "1.11" -> modules_1_11, + "1.13" -> modules_1_13, "1.dev" -> modules_1_dev, ) @@ -68,7 +70,9 @@ class DamlLfEncoderTest val findModules = dar.toOption.toList.flatMap(getNonEmptyModules).toSet - findModules shouldBe expectedModules + findModules diff expectedModules shouldBe Set() + expectedModules diff findModules shouldBe Set() + } } diff --git a/daml-lf/encoder/src/test/scala/com/digitalasset/daml/lf/archive/testing/EncodeV1Spec.scala b/daml-lf/encoder/src/test/scala/com/digitalasset/daml/lf/archive/testing/EncodeV1Spec.scala index 35f7b984c1b5..e57ae6c98332 100644 --- a/daml-lf/encoder/src/test/scala/com/digitalasset/daml/lf/archive/testing/EncodeV1Spec.scala +++ b/daml-lf/encoder/src/test/scala/com/digitalasset/daml/lf/archive/testing/EncodeV1Spec.scala @@ -148,6 +148,13 @@ class EncodeV1Spec extends AnyWordSpec with Matchers with TableDrivenPropertyChe throw @(Update Unit) @Mod:MyException (Mod:MyException {message = "oops"}) catch e -> Some @(Update Unit) (upure @Unit ()) in upure @Unit (); + + val myAnyException: AnyException = + to_any_exception @Mod:MyException (Mod:MyException {message = "oops"}); + + val maybeException: Option Mod:MyException = + from_any_exception @Mod:MyException Mod:myAnyException; + } """