HasField instance for generic variant types used over a data-dependency is not found by LF typechecker.
See original GitHub issueThis is in a package dependency configuration where one package depends on two others, as a data dependency.
package 3
/ \
data / \ data
/ \
package 1 package 2
When defining a two-parameter class within package 3 and an instance of it that links a type from package 1 to one from package 2, the LF typecheck fails (after a successful GHC type check/inference). Suspected cause: attempt to specialise the instance code. But note that no concrete instance is known in this code, all types still have type parameters.
Note that this compiles fine when the dependencies between the packages are full (not data-) dependencies.
data-depend-triangle $ ll
total 20
drwxr-xr-x 5 jost jost 4096 Aug 31 18:03 ./
drwxr-xr-x 13 jost jost 4096 Aug 31 18:02 ../
drwxr-xr-x 4 jost jost 4096 Aug 31 18:10 package1/
drwxr-xr-x 4 jost jost 4096 Aug 31 18:10 package2/
drwxr-xr-x 4 jost jost 4096 Sep 1 09:41 package3/
data-depend-triangle $ more package?/daml.yaml
::::::::::::::
package1/daml.yaml
::::::::::::::
sdk-version: 1.4.0
name: package1
version: 0.0.1000
parties:
- 00001
dependencies:
- daml-prim
- daml-stdlib
source: src
::::::::::::::
package2/daml.yaml
::::::::::::::
sdk-version: 1.4.0
name: package2
version: 0.0.1000
parties:
- 00001
dependencies:
- daml-prim
- daml-stdlib
source: src/
::::::::::::::
package3/daml.yaml
::::::::::::::
sdk-version: 1.4.0
name: package3
version: 0.0.1000
parties:
- 00001
dependencies:
- daml-prim
- daml-stdlib
data-dependencies:
- ../package1/.daml/dist/package1-0.0.1000.dar
- ../package2/.daml/dist/package2-0.0.1000.dar
source: src
data-depend-triangle $ more package?/src/*daml
::::::::::::::
package1/src/Package1File.daml
::::::::::::::
module Package1File where
data AVariant x y = V1 with theX: x
| V2 with theYs: [y]
::::::::::::::
package2/src/Package2File.daml
::::::::::::::
module Package2File where
-- identical to the definition in Package1File
data AVariant x y = V1 with theX: x
| V2 with theYs: [y]
::::::::::::::
package3/src/Package3File.daml
::::::::::::::
daml 1.2
module Package3File where
import Package1File qualified as P1
import Package2File qualified as P2
class Convert a b where
convert : a -> b
instance Convert a a' => Convert [a] [a'] where
convert = fmap convert
instance (Convert x x', Convert y y') =>
Convert (P1.AVariant x y) (P2.AVariant x' y') where
convert = \a -> case a of
P1.V1{} ->
P2.V1 with
theX = convert a.theX
P1.V2{} ->
P2.V2 with
theYs = convert a.theYs
data-depend-triangle $ for i in 1 2 3; do (cd package$i && daml build); done
Compiling package1 to a DAR.
Created .daml/dist/package1-0.0.1000.dar
Compiling package2 to a DAR.
Created .daml/dist/package2-0.0.1000.dar
Compiling package3 to a DAR.
File: src/Package3File.daml
Hidden: no
Range: 1:0-100001:0
Source: DAML-LF typechecker
Severity: DsError
Message:
error type checking value Package3File.$cconvert1:
unknown value:
e196c7990292b3791ab23cab64be3c89edcd06e3707efa7896d504c5ab29f3b4:Package1File:$fHasField"theX"AVariantx_ait
ERROR: Creation of DAR file failed.
data-depend-triangle $
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Covariance and Contravariance in Generics - Microsoft Learn
A generic type parameter that is not marked covariant or contravariant is referred to as invariant. A brief summary of facts about variance ......
Read more >Why doesn't C# support variant generic classes? [duplicate]
It fails to compile with this error: Invalid variance modifier. Only interface and delegate type parameters can be specified as variant. I don't ......
Read more >Daml SDK Documentation
“ Variants. “ Manipulating immutable data. “ Contract keys. After this section, you should be able to use a Daml ledger as a...
Read more >Covariance and contravariance in generic types
We saw above that List[Corgi] is not a subtype of List[Dog] . Therefore, List is not covariant in its type variable. Why is...
Read more >Data.Generics.Record.HasField - Hackage
Records that have a field with a given name. ... Lens focusing on a field with a given name. Compatible with the lens...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks like the generated names are in the typechecked ast (-ddump-tc-ast).
@jberthold-da We fixed this particular issue. It will be part of SDK 1.6.0.