databricks / sjsonnet

Apache License 2.0
267 stars 55 forks source link

Inconsistent Function Manifestation as JSON Across Jsonnet Implementations #201

Open ys-db opened 9 months ago

ys-db commented 9 months ago

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

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

ys-db commented 9 months ago

duplicate of #168