sjsonnet icon indicating copy to clipboard operation
sjsonnet copied to clipboard

Inconsistent Function Manifestation as JSON Across Jsonnet Implementations

Open ys-db opened this issue 1 year ago • 1 comments

Hello,

I’ve encountered an intriguing inconsistency in how functions are converted to JSON across different Jsonnet implementations, specifically between Go/C++, and sjsonnet.

Issue Description

Attempting to manifest a function as JSON output reveals a discrepancy in behavior. The sjsonnet implementation successfully evaluates and converts the function into JSON, whereas the Go and C++ implementations reject it, producing an error.

Code Snippet

❯ sjsonnet -e 'local f() = {v:42};{f:f}'
{
   "f": {
      "v": 42
   }
}

Expected Behavior

Both implementations should ideally align with their handling of function-to-JSON conversion, following the Jsonnet specification closely.

Error in Go Implementation

❯ jsonnet -e 'local f() = {v:42};{f:f}'
RUNTIME ERROR: couldn't manifest function as JSON
	Field "f"
	During manifestation

Related Observation

When modifying the function f to accept a parameter, sjsonnet produces a different error. While C++/Go implementations produce the same error.

Code Snippet with Parameter

❯ sjsonnet -e 'local f(x) = {v:x};{f:f}'
sjsonnet.Error: Function parameter x not bound in call
    at .((materialize) offset:)

Questions

  • Is this behavior (specifically the acceptance of function-to-JSON conversion in sjsonnet) intended and defined within the language spec?

The inconsistent behavior is confusing to users. Understanding this would ensure jsonnet is portable and behaves predictably across environments.

ys-db avatar Feb 17 '24 00:02 ys-db

duplicate of #168

ys-db avatar Feb 17 '24 01:02 ys-db