From 95caad371f28ec32a01990ae9f0906459df4e9c2 Mon Sep 17 00:00:00 2001 From: Dylan Thinnes Date: Fri, 27 Sep 2024 11:49:03 +0100 Subject: [PATCH 1/2] Add two tests for Phantom type, fix error messages --- .../daml-lf-tools/src/DA/Daml/LF/TypeChecker/Error.hs | 4 ++-- sdk/compiler/damlc/tests/BUILD.bazel | 1 + sdk/compiler/damlc/tests/src/DA/Test/DamlcUpgrades.hs | 11 +++++++++-- sdk/test-common/BUILD.bazel | 1 + .../upgrades/SucceedWhenParamNameChanges/v1/Main.daml | 4 ++-- .../upgrades/SucceedWhenParamNameChanges/v2/Main.daml | 3 ++- .../SucceedWhenPhantomParamBecomesUsed/v1/Main.daml | 8 ++++++++ .../SucceedWhenPhantomParamBecomesUsed/v2/Main.daml | 7 +++++++ 8 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 sdk/test-common/src/main/daml/upgrades/SucceedWhenPhantomParamBecomesUsed/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/SucceedWhenPhantomParamBecomesUsed/v2/Main.daml diff --git a/sdk/compiler/daml-lf-tools/src/DA/Daml/LF/TypeChecker/Error.hs b/sdk/compiler/daml-lf-tools/src/DA/Daml/LF/TypeChecker/Error.hs index 121efe93d79d..0d9a1ee0a381 100644 --- a/sdk/compiler/daml-lf-tools/src/DA/Daml/LF/TypeChecker/Error.hs +++ b/sdk/compiler/daml-lf-tools/src/DA/Daml/LF/TypeChecker/Error.hs @@ -696,8 +696,8 @@ instance Pretty UnwarnableError where pprintDep (pkgId, Just meta) = pPrint pkgId <> "(" <> pPrint (packageName meta) <> ", " <> pPrint (packageVersion meta) <> ")" pprintDep (pkgId, Nothing) = pPrint pkgId EUpgradeMultiplePackagesWithSameNameAndVersion name version ids -> "Multiple packages with name " <> pPrint name <> " and version " <> pPrint (show version) <> ": " <> hcat (L.intersperse ", " (map pPrint ids)) - EUpgradeDifferentParamsCount origin -> "EUpgradeDifferentParamsCount " <> pPrint origin - EUpgradeDifferentParamsKinds origin -> "EUpgradeDifferentParamsKinds " <> pPrint origin + EUpgradeDifferentParamsCount origin -> "The upgraded " <> pPrint origin <> " has changed the number of type variables it has." + EUpgradeDifferentParamsKinds origin -> "The upgraded " <> pPrint origin <> " has changed the kind of one of its type variables." instance Pretty UpgradedRecordOrigin where diff --git a/sdk/compiler/damlc/tests/BUILD.bazel b/sdk/compiler/damlc/tests/BUILD.bazel index 6cd64fc315e8..2c3a6c5cde18 100644 --- a/sdk/compiler/damlc/tests/BUILD.bazel +++ b/sdk/compiler/damlc/tests/BUILD.bazel @@ -526,6 +526,7 @@ da_haskell_test( "//test-common:upgrades-WarnsWhenTemplateChangesKeyMaintainers-files", "//test-common:upgrades-WarnsWhenTemplateChangesObservers-files", "//test-common:upgrades-WarnsWhenTemplateChangesSignatories-files", + "//test-common:upgrades-SucceedWhenPhantomParamBecomesUsed-files", ], hackage_deps = [ "base", diff --git a/sdk/compiler/damlc/tests/src/DA/Test/DamlcUpgrades.hs b/sdk/compiler/damlc/tests/src/DA/Test/DamlcUpgrades.hs index 329c9e586314..c43a96bcc859 100644 --- a/sdk/compiler/damlc/tests/src/DA/Test/DamlcUpgrades.hs +++ b/sdk/compiler/damlc/tests/src/DA/Test/DamlcUpgrades.hs @@ -620,14 +620,14 @@ tests damlc = version1_dev , test "FailWhenParamCountChanges" - (FailWithError "\ESC\\[0;91merror type checking data type Main.MyStruct:\n EUpgradeDifferentParamsCount") + (FailWithError "\ESC\\[0;91merror type checking data type Main.MyStruct:\n The upgraded data type MyStruct has changed the number of type variables it has.") versionDefault NoDependencies False True , test "FailWhenParamKindChanges" - (FailWithError "\ESC\\[0;91merror type checking data type Main.MyStruct:\n EUpgradeDifferentParamsKinds") + (FailWithError "\ESC\\[0;91merror type checking data type Main.MyStruct:\n The upgraded data type MyStruct has changed the kind of one of its type variables.") versionDefault NoDependencies False @@ -639,6 +639,13 @@ tests damlc = NoDependencies False True + , test + "SucceedWhenPhantomParamBecomesUsed" + Succeed + versionDefault + NoDependencies + False + True ] ) where diff --git a/sdk/test-common/BUILD.bazel b/sdk/test-common/BUILD.bazel index 9254ca56cea2..3cdea57310d8 100644 --- a/sdk/test-common/BUILD.bazel +++ b/sdk/test-common/BUILD.bazel @@ -506,6 +506,7 @@ da_scala_dar_resources_library( ("FailWhenParamCountChanges", {}, {}), ("FailWhenParamKindChanges", {}, {}), ("SucceedWhenParamNameChanges", {}, {}), + ("SucceedWhenPhantomParamBecomesUsed", {}, {}), ] ] diff --git a/sdk/test-common/src/main/daml/upgrades/SucceedWhenParamNameChanges/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/SucceedWhenParamNameChanges/v1/Main.daml index 7dce9f05778a..43465e5464f9 100644 --- a/sdk/test-common/src/main/daml/upgrades/SucceedWhenParamNameChanges/v1/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/SucceedWhenParamNameChanges/v1/Main.daml @@ -3,5 +3,5 @@ module Main where -data MyStruct a = MyStruct { field1 : a } - +data MyStruct1 a = MyStruct1 { field1 : a } +data MyStruct2 a b = MyStruct2 { field1 : a } diff --git a/sdk/test-common/src/main/daml/upgrades/SucceedWhenParamNameChanges/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/SucceedWhenParamNameChanges/v2/Main.daml index 5aae2347219a..0cc0dfbedd0a 100644 --- a/sdk/test-common/src/main/daml/upgrades/SucceedWhenParamNameChanges/v2/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/SucceedWhenParamNameChanges/v2/Main.daml @@ -3,5 +3,6 @@ module Main where -data MyStruct b = MyStruct { field1 : b } +data MyStruct1 b = MyStruct1 { field1 : b } +data MyStruct2 b a = MyStruct2 { field1 : b, field2 : Optional a, field3: Optional b } diff --git a/sdk/test-common/src/main/daml/upgrades/SucceedWhenPhantomParamBecomesUsed/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/SucceedWhenPhantomParamBecomesUsed/v1/Main.daml new file mode 100644 index 000000000000..6da04c01e80f --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/SucceedWhenPhantomParamBecomesUsed/v1/Main.daml @@ -0,0 +1,8 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where + +data MyStruct a b = MyStruct { field1 : a } + + diff --git a/sdk/test-common/src/main/daml/upgrades/SucceedWhenPhantomParamBecomesUsed/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/SucceedWhenPhantomParamBecomesUsed/v2/Main.daml new file mode 100644 index 000000000000..1641788af413 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/SucceedWhenPhantomParamBecomesUsed/v2/Main.daml @@ -0,0 +1,7 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where + +data MyStruct a b = MyStruct { field1 : a, field2 : Optional b } + From c0cfd4e9d8f476e529686962ffb1e0cb23607c54 Mon Sep 17 00:00:00 2001 From: Dylan Thinnes Date: Fri, 27 Sep 2024 12:09:50 +0100 Subject: [PATCH 2/2] lint --- sdk/compiler/damlc/tests/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/compiler/damlc/tests/BUILD.bazel b/sdk/compiler/damlc/tests/BUILD.bazel index 2c3a6c5cde18..eba1e2ffea95 100644 --- a/sdk/compiler/damlc/tests/BUILD.bazel +++ b/sdk/compiler/damlc/tests/BUILD.bazel @@ -488,6 +488,7 @@ da_haskell_test( "//test-common:upgrades-RecordFieldsNewNonOptional-files", "//test-common:upgrades-SucceedWhenATopLevelEnumAddsAField-files", "//test-common:upgrades-SucceedWhenParamNameChanges-files", + "//test-common:upgrades-SucceedWhenPhantomParamBecomesUsed-files", "//test-common:upgrades-SucceedsWhenATopLevelEnumChanges-files", "//test-common:upgrades-SucceedsWhenATopLevelRecordAddsAnOptionalFieldAtTheEnd-files", "//test-common:upgrades-SucceedsWhenATopLevelRecordAddsAnOptionalFieldAtTheEnd-v1.dar", @@ -526,7 +527,6 @@ da_haskell_test( "//test-common:upgrades-WarnsWhenTemplateChangesKeyMaintainers-files", "//test-common:upgrades-WarnsWhenTemplateChangesObservers-files", "//test-common:upgrades-WarnsWhenTemplateChangesSignatories-files", - "//test-common:upgrades-SucceedWhenPhantomParamBecomesUsed-files", ], hackage_deps = [ "base",