Skip to content

Commit

Permalink
Add two tests for Phantom type, fix error messages (#20024)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylant-da authored Sep 27, 2024
1 parent 421a1a6 commit d565082
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions sdk/compiler/damlc/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 9 additions & 2 deletions sdk/compiler/damlc/tests/src/DA/Test/DamlcUpgrades.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -639,6 +639,13 @@ tests damlc =
NoDependencies
False
True
, test
"SucceedWhenPhantomParamBecomesUsed"
Succeed
versionDefault
NoDependencies
False
True
]
)
where
Expand Down
1 change: 1 addition & 0 deletions sdk/test-common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ da_scala_dar_resources_library(
("FailWhenParamCountChanges", {}, {}),
("FailWhenParamKindChanges", {}, {}),
("SucceedWhenParamNameChanges", {}, {}),
("SucceedWhenPhantomParamBecomesUsed", {}, {}),
]
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Original file line number Diff line number Diff line change
@@ -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 }


Original file line number Diff line number Diff line change
@@ -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 }

0 comments on commit d565082

Please sign in to comment.