Skip to content

make _lookupNByKey return an Optional#193

Merged
roger-bosman-da merged 1 commit intoda-master-8.8.1from
roger/lookupnbykey-to-optional
Apr 21, 2026
Merged

make _lookupNByKey return an Optional#193
roger-bosman-da merged 1 commit intoda-master-8.8.1from
roger/lookupnbykey-to-optional

Conversation

@roger-bosman-da
Copy link
Copy Markdown
Contributor

@roger-bosman-da roger-bosman-da commented Apr 9, 2026

In theory, damlc catches calls to lookupbykey with negative (yielding an error) or 0 (yielding the empty list []) n. That being said, to accomodate handwritten LF and to be a bit more precies, we wrap the lookupbykey in an optional, where None indicates failiure (such as a n < 1).

This PR implements the GHC side of this change

Daml companion PR: digital-asset/daml#22894
Canton companion PR: https://github.com/DACH-NY/canton/pull/32018

@roger-bosman-da roger-bosman-da merged commit 07bb3ec into da-master-8.8.1 Apr 21, 2026
roger-bosman-da added a commit to digital-asset/daml that referenced this pull request Apr 24, 2026
In theory, `damlc` catches calls to lookupbykey with negative (yielding
an error) or 0 (yielding the empty list `[]`) n. That being said, to
accomodate handwritten LF and to be a bit more precies, we wrap the
`lookupbykey` in an optional, where `None` indicates failiure (such as a
n < 1).

This PR implements the daml side of this change. 

- Change "the staging version" (compiler always just knows of 1) to rc2
- Change the type of the builtin `ULookupNByKey` to include an Optional
- alter `lookupNByKey` to force the Optional, yielding an error if it is
None (it should never be None when compiling with damlc, since `n < 1`
is already caught by the implementation of `lookupNByKey`
- move all lookup functions to Prelude and hide/reexport what needs to
be in DA.ContractKeys (this way `lookupByKey` can use `lookupNByKey` and
does not have to repeat the fromOption`)
- updated haddoc (fixes
#22673)

Furthermore, since the change involves a change to the daml-lf json, the
golden check was uncommented as well.

Canton companion PR: DACH-NY/canton#32018
GHC companion PR: digital-asset/ghc#193

Steps taken:
1. [DONE] Daml ad-hoc release that sets type to optional 
2. [DONE] Canton ad-hoc release with DamlScriptIT tests (the only one
who use daml) disabled
3. [DONE] Daml ad-hoc release depending on canton ad-hoc of step 2
4. [DONE] Merge canton in main depending on daml ad-hoc of step 3
4. [IN PROGRESS] Merge sdk in main depending on canton snapshot of step
4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants