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

Prevent changing meaning of std in desugared expressions #69

Open
sbarzowski opened this issue Sep 20, 2017 · 4 comments · Fixed by CertainLach/jrsonnet#19
Open

Prevent changing meaning of std in desugared expressions #69

sbarzowski opened this issue Sep 20, 2017 · 4 comments · Fixed by CertainLach/jrsonnet#19

Comments

@sbarzowski
Copy link
Collaborator

sbarzowski commented Sep 20, 2017

Some constructs are desugared to functions from std. The problem is that if the user wraps them in their own definition of std they can change the meaning of core language constructs (probably just break them) which will be extremely confusing.

We can have special alias for std, unavailable for the user, for example $td.

@sparkprime
Copy link
Contributor

This is also a bug in the C++ version I think?

@sparkprime
Copy link
Contributor

Short answer is "yes":

$ jsonnet -e '1 == 1'
true
$ jsonnet -e 'local std2 = std; local std = std2 { primitiveEquals(a, b):: false }; 1 == 1'
false

@sbarzowski sbarzowski added the bug label Feb 2, 2020
CertainLach added a commit to CertainLach/jrsonnet that referenced this issue Oct 19, 2020
Also removes intrinsic interface for natives, they weren't useable for users
anyway, and we have native callback support now.

Fixes google/jsonnet#378
Fixes google/go-jsonnet#69

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>
@netomi
Copy link
Contributor

netomi commented Aug 12, 2023

shouldn't std be just a reserved keyword which can not be used to create a local?

@CertainLach
Copy link

In jrsonnet, I have fixed this by not desugaring and instead implementing the comparison/mod (formatting) operator directly.
https://github.com/CertainLach/jrsonnet/blob/master/crates/jrsonnet-evaluator/src/evaluate/operator.rs#L141

In sjsonnet they have implemented the same approach.
https://github.com/databricks/sjsonnet/blob/master/sjsonnet/src/sjsonnet/Evaluator.scala#L363

(This caused some problems: in jrsonnet, stdlib is not special, but the separate library, same as any user can write when using jrsonnet as a library, so formatting/comparison are implemented in core language, and not in the stdlib. I don't think this applies to cpp-jsonnet/go-jsonnet, though.)
https://github.com/CertainLach/jrsonnet/blob/master/crates/jrsonnet-stdlib/src/lib.rs

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

Successfully merging a pull request may close this issue.

4 participants