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

Bug when handling assert statements #21

Closed
mgyucht opened this issue Jun 18, 2019 · 1 comment · Fixed by #172
Closed

Bug when handling assert statements #21

mgyucht opened this issue Jun 18, 2019 · 1 comment · Fixed by #172

Comments

@mgyucht
Copy link
Contributor

mgyucht commented Jun 18, 2019

Discovered the following behavior difference between sjsonnet and jsonnet.

test.jsonnet:

// Returns true if any key from base is overridden in object
local isAnyKeyOverridden = function (base, object)
  local keys = std.objectFields(base);
  std.foldl(function(acc, field) acc || base[field] != object[field], keys, false);

local base = {
  paramA: null,
  paramB: null,
};

base + {
  assert !isAnyKeyOverridden(base, $),
}

test2.jsonnet:

local base = import "test.jsonnet";
local Parameterized = base + { paramA:: 3 };
Parameterized

Output from jsonnet test2.jsonnet:

RUNTIME ERROR: Object assertion failed.
        ../universe/test.jsonnet:12:10-38       thunk <object_assert>
        During manifestation

Output from sjsonnet test2.jsonnet:

{
   "paramB": null
}
@rschatz
Copy link

rschatz commented Sep 13, 2022

I think I have also run into this bug, and I have found a simpler reproducer:

{ } + {
    assert false
}

With jsonnet this fails, with sjsonnet it just returns { }.

Apparently, when combining objects, it's ignoring assertions from the second object. Putting the assertion in the first object makes it fail as expected.

In the original bug report, if you switch the + around, it also fails as expected:

{
  assert !isAnyKeyOverridden(base, $),
} + base

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 a pull request may close this issue.

2 participants