cue: support new-style definitions in LookupDef

Closes #360

Change-Id: I9efeb9fc5fdfa5f4e34dc66997a8648eac172aa9
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5822
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
diff --git a/cue/types.go b/cue/types.go
index a77b029..f21a7bd 100644
--- a/cue/types.go
+++ b/cue/types.go
@@ -1475,10 +1475,10 @@
 		return newErrValue(v, err)
 	}
 
-	f := v.ctx().strLabel(name)
+	f := v.ctx().label(name, true)
 	for i, a := range o.arcs {
 		if a.feature == f {
-			if !a.definition || a.optional {
+			if f&hidden != 0 || !a.definition || a.optional {
 				break
 			}
 			return newChildValue(&o, i)
diff --git a/cue/types_test.go b/cue/types_test.go
index 2320bc4..5d7a880 100644
--- a/cue/types_test.go
+++ b/cue/types_test.go
@@ -842,6 +842,41 @@
 	}
 }
 
+func TestValue_LookupDef(t *testing.T) {
+	r := &Runtime{}
+
+	testCases := []struct {
+		in     string
+		def    string // comma-separated path
+		exists bool
+		out    string
+	}{{
+		in:  `#foo: 3`,
+		def: "#foo",
+		out: `3`,
+	}, {
+		in:  `_foo: 3`,
+		def: "_foo",
+		out: `_|_(defintion "_foo" not found)`,
+	}, {
+		in:  `#_foo: 3`,
+		def: "#_foo",
+		out: `_|_(defintion "#_foo" not found)`,
+	}}
+
+	for _, tc := range testCases {
+		t.Run(tc.def, func(t *testing.T) {
+			v := compile(t, r, tc.in).Value()
+			v = v.LookupDef(tc.def)
+			got := fmt.Sprint(v)
+
+			if got != tc.out {
+				t.Errorf("\ngot:  %s\nwant: %s", got, tc.out)
+			}
+		})
+	}
+}
+
 func TestDefaults(t *testing.T) {
 	testCases := []struct {
 		value string