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

std.mergePatch should create resulting object fields at Normal visibility, not Unhide #255

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sjsonnet/src/sjsonnet/Std.scala
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ class Std(private val additionalNativeFunctions: Map[String, Val.Builtin] = Map.
builtin(Range),
builtin("mergePatch", "target", "patch"){ (pos, ev, target: Val, patch: Val) =>
val mergePosition = pos
def createMember(v: => Val) = new Val.Obj.Member(false, Visibility.Unhide) {
def createMember(v: => Val) = new Val.Obj.Member(false, Visibility.Normal) {
def invoke(self: Val.Obj, sup: Val.Obj, fs: FileScope, ev: EvalScope): Val = v
}
def recPair(l: Val, r: Val): Val = (l, r) match{
Expand Down
17 changes: 17 additions & 0 deletions sjsonnet/test/src/sjsonnet/StdMergePatchTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,22 @@ object StdMergePatchTests extends TestSuite {
// It's also lost in nested fields:
eval("{a: {b: 1}} + std.mergePatch({a: {b +: 2}}, {})") ==> ujson.Obj("a" -> ujson.Obj("b" -> 2))
}

test("default visibility of resulting fields") {
// In v0.20.0 of google/jsonnet, the following returned `{a: 1}`, not `{}`:
eval("{a:: 0} + std.mergePatch({a: 1}, {})") ==> ujson.Obj()
eval("({a:: 0} + std.mergePatch({a: 1}, {})).a") ==> ujson.Num(1)
// However, go-jsonnet v0.20.0 returned `{}`. This difference arose because the pure-jsonnet
// implementation of `std.mergePatch` used object comprehensions in its implementation and
// the two implementations differed in the default visibility of fields in the reuslting
// object. See https://github.com/google/jsonnet/issues/1111
// google/jsonnet merged a change to match go-jsonnet's behavior in a future version:
// https://github.com/google/jsonnet/pull/1140
// Interestingly, sjsonnet already matched go-jsonnet's behavior for object comprehensions
// because the following already returned `{}`; our previous behavior difference was only
// for mergePatch results:
eval("""{a:: 0} + {[a]: 1 for a in ["a"]}""") ==> ujson.Obj()
eval("""({a:: 0} + {[a]: 1 for a in ["a"]}).a""") ==> ujson.Num(1)
}
}
}
Loading