jsonnet icon indicating copy to clipboard operation
jsonnet copied to clipboard

Behavior of `std` overriding and desugaring.

Open eduardosm opened this issue 1 year ago • 1 comments

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.

eduardosm avatar Feb 04 '24 12:02 eduardosm

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.

sparkprime avatar Feb 18 '24 13:02 sparkprime