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

Behavior of std overriding and desugaring. #1128

Open
eduardosm opened this issue Feb 4, 2024 · 1 comment · May be fixed by #1158
Open

Behavior of std overriding and desugaring. #1128

eduardosm opened this issue Feb 4, 2024 · 1 comment · May be fixed by #1158

Comments

@eduardosm
Copy link

Go implementation differs from C++ implementation when overriding the std binding and invoking an operator that desugars to a std library call.

For example with

local std = {}; 1 == 1

which would desugar to

local std = /* std.jsonnet */; local std = {}; std.equals(1, 1)

The C++ implementation fails:

RUNTIME ERROR: field does not exist: equals

while the Go implementation prints true.

To me, the Go behavior makes for sense than the C++ one, since breaking syntax constructs by overriding a binding seems weird. However, the C++ behavior is closer to what the "Desugaring" section of the specification mandates.

The Go implementation behaves as if it desugared to something like

local std = /* std.jsonnet */; local std = {}; (/* std.jsonnet */).equals(1, 1)

I think it would be nice to have consistent behavior across implementations, and have such behavior written in the specification.

@sparkprime
Copy link
Member

The optimisations that replace std functions with their native equivalents need to be aware that std has been redefined, which shouldn't be too hard to implement.

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