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

Commit

Permalink
cue: allow LookupDef on embedded scalars
Browse files Browse the repository at this point in the history
Fixes #617

Change-Id: Ib637ef0c5b418c81d0187f4995f1a015794a3620
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8341
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
  • Loading branch information
mpvl committed Jan 28, 2021
1 parent 76a72c4 commit ba8eb37
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cue/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1340,16 +1340,20 @@ func (v Value) structValData(ctx *context) (structValue, *adt.Bottom) {
}

func (v Value) structValFull(ctx *context) (structValue, *adt.Bottom) {
return v.structValOpts(ctx, options{})
return v.structValOpts(ctx, options{allowScalar: true})
}

// structVal returns an structVal or an error if v is not a struct.
func (v Value) structValOpts(ctx *context, o options) (structValue, *adt.Bottom) {
func (v Value) structValOpts(ctx *context, o options) (s structValue, err *adt.Bottom) {
v, _ = v.Default()

obj, err := v.getStruct()
if err != nil {
return structValue{}, err
obj := v.v

if !o.allowScalar {
obj, err = v.getStruct()
if err != nil {
return structValue{}, err
}
}

features := export.VertexFeatures(obj)
Expand Down Expand Up @@ -1949,6 +1953,7 @@ type options struct {
ignoreClosedness bool // used for comparing APIs
docs bool
disallowCycles bool // implied by concrete
allowScalar bool
}

// An Option defines modes of evaluation.
Expand Down
4 changes: 4 additions & 0 deletions cue/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,10 @@ func TestValue_LookupDef(t *testing.T) {
in: `_#foo: 3`,
def: "_#foo",
out: `_|_ // definition "_#foo" not found`,
}, {
in: `"foo", #foo: 3`,
def: "#foo",
out: `3`,
}}

for _, tc := range testCases {
Expand Down

0 comments on commit ba8eb37

Please sign in to comment.