Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple contracts on a record not working as intended #2041

Closed
alialabbas opened this issue Sep 15, 2024 · 2 comments · Fixed by #2042
Closed

Multiple contracts on a record not working as intended #2041

alialabbas opened this issue Sep 15, 2024 · 2 comments · Fixed by #2042
Labels

Comments

@alialabbas
Copy link

Describe the bug
Typically, the following code would apply multiple contracts on a value and if value is a negative number it would fail on the second part of the contract.

-123 | Number | std.number.PosNat 

However, this is not the case when applying multiple record contracts and both have the same set of fields. The snippet below should have failed when evaluating container but it doesn't. Based on my testing, this only happens when both inner and outer have the same of fields and adding an additional field to either contracts would give the expected behavior.

let outer = {
  spec
    | {
      hostAliases | Number | optional,
      containers | Number | optional,
      ..
    }
    | optional,
  ..
}
in
let inner = {

  spec
    | {
      hostAliases
        | optional,
      containers
        | Array {
          ..
        },
      ..
    }
    | optional,
  ..
}
in
{
  spec = {
    hostAliases = "this should have failed",
    containers = [
      {
        name = "test",
        image = "nginx",
        ports = [
          {
            containerPort = 80,
            name = "http"
          }
        ],
      }
    ]
  }
} | inner | outer 

Expected behavior
{} | contract1 | contract2 should work when both contracts run checks against the same set of fields.

Environment

  • OS name + version: NixOS 24..05
  • Version of the code: 1.8.0
@yannham yannham added type: bug area: contracts P1 critical: next release labels Sep 16, 2024
@yannham
Copy link
Member

yannham commented Sep 16, 2024

Thanks for the report. I can reproduce on 1.8.0, and the optional don't play any role here - the bug still happens if we remove them all. The .. are also not necessary for the repro. The bug was already present in 1.7.0 and 1.6.0. I'll bisect to see when it started, but I think we should make a minor release once it's fixed - silently ignoring contracts is bad.

Given the fact that adding a field to either record fixes the issue, I'm highly suspecting that the contract deduplication optimization isn't sound and consider the two contracts to be equivalent for some reasons, thus eliding the second one.

@yannham
Copy link
Member

yannham commented Sep 16, 2024

(Note: first bad commit is 2a727ba, which does touch the record contract equality code to ignore pending contracts)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants