Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
cue: detect incomplete value for value method
Browse files Browse the repository at this point in the history
Builtins should typically not accept incomplete values.
This was mostly detected, but not for the value method.

Fixes #234.

Change-Id: Ie51de9ca20b38fa13fce2c24ccf609a78f0d9e9f
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/4387
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Dec 17, 2019
1 parent c82a793 commit 1fecca8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cue/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,13 @@ func (c *callCtxt) errf(src source, underlying error, format string, args ...int
}

func (c *callCtxt) value(i int) Value {
return newValueRoot(c.ctx, c.args[i])
v := newValueRoot(c.ctx, c.args[i])
v, _ = v.Default()
if !v.IsConcrete() {
c.errf(c.src, v.toErr(c.ctx.mkErr(c.src, codeIncomplete,
"non-concrete value")), "incomplete")
}
return v
}

func (c *callCtxt) structVal(i int) *Struct {
Expand Down
9 changes: 9 additions & 0 deletions cue/resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2845,6 +2845,15 @@ func TestFullEval(t *testing.T) {
}
`,
out: `<0>{x: 1, y: <1>{x: 2, z: 1}}`,
}, {
desc: "don't pass incomplete values to builtins",
in: `
import "encoding/json"
input: string
foo: json.Marshal(input)
`,
out: `<0>{input: string, foo: <1>.Marshal (<2>.input)}`,
}}
rewriteHelper(t, testCases, evalFull)
}
Expand Down

0 comments on commit 1fecca8

Please sign in to comment.