cue: allow LookupDef on embedded scalars

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>
diff --git a/cue/types.go b/cue/types.go
index 88e5660..e140bee 100644
--- a/cue/types.go
+++ b/cue/types.go
@@ -1340,16 +1340,20 @@
 }
 
 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)
@@ -1949,6 +1953,7 @@
 	ignoreClosedness  bool // used for comparing APIs
 	docs              bool
 	disallowCycles    bool // implied by concrete
+	allowScalar       bool
 }
 
 // An Option defines modes of evaluation.
diff --git a/cue/types_test.go b/cue/types_test.go
index 925d3a9..e3b7ab0 100644
--- a/cue/types_test.go
+++ b/cue/types_test.go
@@ -1001,6 +1001,10 @@
 		in:  `_#foo: 3`,
 		def: "_#foo",
 		out: `_|_ // definition "_#foo" not found`,
+	}, {
+		in:  `"foo", #foo: 3`,
+		def: "#foo",
+		out: `3`,
 	}}
 
 	for _, tc := range testCases {