Skip to content

Commit

Permalink
internal: remove some deprecated type/method usages
Browse files Browse the repository at this point in the history
Some usages of the following deprecated types and methods are replaced
by their non-deprecated equivalents:

    - cue.Runtime
    - Value.Lookup
    - ast.Node.AddComment

Updates #2480.

Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Change-Id: I501fbdc518b3edf122ec13b751502f15e2372244
  • Loading branch information
NoamTD committed May 14, 2024
1 parent 3b19168 commit c7117db
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions internal/core/dep/dep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"text/tabwriter"

"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
"cuelang.org/go/cue/format"
"cuelang.org/go/internal/core/adt"
"cuelang.org/go/internal/core/debug"
Expand Down Expand Up @@ -130,15 +131,14 @@ func TestX(t *testing.T) {
t.Skip()
}

rt := cue.Runtime{}
inst, err := rt.Compile("", in)
if err != nil {
v := cuecontext.New().CompileString(in)
if err := v.Err(); err != nil {
t.Fatal(err)
}

v := inst.Lookup("a")
aVal := v.LookupPath(cue.MakePath(cue.Str("a")))

r, n := value.ToInternal(v)
r, n := value.ToInternal(aVal)

ctxt := eval.NewContext(r, n)

Expand Down
7 changes: 4 additions & 3 deletions internal/core/export/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package export_test
import (
"testing"

"golang.org/x/tools/txtar"

"cuelang.org/go/cue"
"cuelang.org/go/cue/ast"
"cuelang.org/go/cue/cuecontext"
Expand All @@ -34,7 +36,6 @@ import (
"cuelang.org/go/internal/cuetdtest"
"cuelang.org/go/internal/cuetxtar"
"cuelang.org/go/internal/value"
"golang.org/x/tools/txtar"
)

func TestDefinition(t *testing.T) {
Expand Down Expand Up @@ -310,8 +311,8 @@ func TestFromGo(t *testing.T) {
A: "a",
B: "b",
}
var r cue.Runtime
codec := gocodec.New(&r, nil)
ctx := cuecontext.New()
codec := gocodec.New(ctx, nil)
v, err := codec.Decode(m)
if err != nil {
panic(err)
Expand Down
8 changes: 4 additions & 4 deletions internal/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Context struct {
}

func (c *Context) Lookup(field string) cue.Value {
f := c.Obj.Lookup(field)
f := c.Obj.LookupPath(cue.MakePath(cue.Str(field)))
if !f.Exists() {
c.addErr(f, nil, "could not find field %q", field)
return cue.Value{}
Expand All @@ -51,7 +51,7 @@ func (c *Context) Lookup(field string) cue.Value {
}

func (c *Context) Int64(field string) int64 {
f := c.Obj.Lookup(field)
f := c.Obj.LookupPath(cue.MakePath(cue.Str(field)))
value, err := f.Int64()
if err != nil {
c.addErr(f, err, "invalid integer argument")
Expand All @@ -61,7 +61,7 @@ func (c *Context) Int64(field string) int64 {
}

func (c *Context) String(field string) string {
f := c.Obj.Lookup(field)
f := c.Obj.LookupPath(cue.MakePath(cue.Str(field)))
value, err := f.String()
if err != nil {
c.addErr(f, err, "invalid string argument")
Expand All @@ -71,7 +71,7 @@ func (c *Context) String(field string) string {
}

func (c *Context) Bytes(field string) []byte {
f := c.Obj.Lookup(field)
f := c.Obj.LookupPath(cue.MakePath(cue.Str(field)))
value, err := f.Bytes()
if err != nil {
c.addErr(f, err, "invalid bytes argument")
Expand Down
4 changes: 2 additions & 2 deletions internal/third_party/yaml/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (d *decoder) attachDocComments(m yaml_mark_t, pos int8, expr ast.Node) {
line = c.mark.line
}
if len(comments) > 0 {
expr.AddComment(&ast.CommentGroup{
ast.AddComment(expr, &ast.CommentGroup{
Doc: pos == 0 && line+1 == m.line,
Position: pos,
List: comments,
Expand All @@ -317,7 +317,7 @@ func (d *decoder) attachLineComment(m yaml_mark_t, pos int8, expr ast.Node) {
Slash: d.pos(c.mark),
Text: "//" + c.text[1:],
}
expr.AddComment(&ast.CommentGroup{
ast.AddComment(expr, &ast.CommentGroup{
Line: true,
Position: pos,
List: []*ast.Comment{comment},
Expand Down

0 comments on commit c7117db

Please sign in to comment.