encoding/gocode: use FieldByName in generated code

The code generated by `encoding/gocode` is triggering a deprecation warning:

```
cuegenInstance.LookupField is deprecated: this API does not work with new-style definitions. Use FieldByName defined on inst.Value().  (SA1019)
```

This change uses the advice from the deprecation and makes the target code use `.Value().FieldByName(...)` instead of `LookupField` on the instance.

Closes #664
https://github.com/cuelang/cue/pull/664

GitOrigin-RevId: 350f28fe93087a001f4b97b67bca126fc75bb1ab
Change-Id: Ice766a561fd15ee92b203e660e44c679b591d2d5
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8381
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/encoding/gocode/templates.go b/encoding/gocode/templates.go
index 34dd25c..23c716e 100644
--- a/encoding/gocode/templates.go
+++ b/encoding/gocode/templates.go
@@ -81,7 +81,7 @@
 // {{.prefix}}Make is called in the init phase to initialize CUE values for
 // validation functions.
 func {{.prefix}}Make(name string, x interface{}) cue.Value {
-	f, err := {{.prefix}}Instance.LookupField(name)
+	f, err := {{.prefix}}Instance.Value().FieldByName(name, true)
 	if err != nil {
 		panic(fmt.Errorf("could not find type %q in instance", name))
 	}
diff --git a/encoding/gocode/testdata/pkg1/cue_gen.go b/encoding/gocode/testdata/pkg1/cue_gen.go
index 05e313c..b88699e 100644
--- a/encoding/gocode/testdata/pkg1/cue_gen.go
+++ b/encoding/gocode/testdata/pkg1/cue_gen.go
@@ -66,7 +66,7 @@
 // cuegenMake is called in the init phase to initialize CUE values for
 // validation functions.
 func cuegenMake(name string, x interface{}) cue.Value {
-	f, err := cuegenInstance.LookupField(name)
+	f, err := cuegenInstance.Value().FieldByName(name, true)
 	if err != nil {
 		panic(fmt.Errorf("could not find type %q in instance", name))
 	}
diff --git a/encoding/gocode/testdata/pkg2/cue_gen.go b/encoding/gocode/testdata/pkg2/cue_gen.go
index 5fe1aa8..3e31508 100644
--- a/encoding/gocode/testdata/pkg2/cue_gen.go
+++ b/encoding/gocode/testdata/pkg2/cue_gen.go
@@ -40,7 +40,7 @@
 // cuegenMake is called in the init phase to initialize CUE values for
 // validation functions.
 func cuegenMake(name string, x interface{}) cue.Value {
-	f, err := cuegenInstance.LookupField(name)
+	f, err := cuegenInstance.Value().FieldByName(name, true)
 	if err != nil {
 		panic(fmt.Errorf("could not find type %q in instance", name))
 	}