Skip to content

Commit 84fe1b9

Browse files
NoamTDmvdan
authored andcommitted
internal: remove some deprecated type/method usages
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 <[email protected]> Change-Id: I501fbdc518b3edf122ec13b751502f15e2372244 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194692 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 1dcd350 commit 84fe1b9

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

internal/core/dep/dep_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"text/tabwriter"
2323

2424
"cuelang.org/go/cue"
25+
"cuelang.org/go/cue/cuecontext"
2526
"cuelang.org/go/cue/format"
2627
"cuelang.org/go/internal/core/adt"
2728
"cuelang.org/go/internal/core/debug"
@@ -130,15 +131,14 @@ func TestX(t *testing.T) {
130131
t.Skip()
131132
}
132133

133-
rt := cue.Runtime{}
134-
inst, err := rt.Compile("", in)
135-
if err != nil {
134+
v := cuecontext.New().CompileString(in)
135+
if err := v.Err(); err != nil {
136136
t.Fatal(err)
137137
}
138138

139-
v := inst.Lookup("a")
139+
aVal := v.LookupPath(cue.MakePath(cue.Str("a")))
140140

141-
r, n := value.ToInternal(v)
141+
r, n := value.ToInternal(aVal)
142142

143143
ctxt := eval.NewContext(r, n)
144144

internal/core/export/export_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package export_test
1717
import (
1818
"testing"
1919

20+
"golang.org/x/tools/txtar"
21+
2022
"cuelang.org/go/cue"
2123
"cuelang.org/go/cue/ast"
2224
"cuelang.org/go/cue/cuecontext"
@@ -34,7 +36,6 @@ import (
3436
"cuelang.org/go/internal/cuetdtest"
3537
"cuelang.org/go/internal/cuetxtar"
3638
"cuelang.org/go/internal/value"
37-
"golang.org/x/tools/txtar"
3839
)
3940

4041
func TestDefinition(t *testing.T) {
@@ -310,8 +311,8 @@ func TestFromGo(t *testing.T) {
310311
A: "a",
311312
B: "b",
312313
}
313-
var r cue.Runtime
314-
codec := gocodec.New(&r, nil)
314+
ctx := cuecontext.New()
315+
codec := gocodec.New(ctx, nil)
315316
v, err := codec.Decode(m)
316317
if err != nil {
317318
panic(err)

internal/task/task.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Context struct {
3939
}
4040

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

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

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

7373
func (c *Context) Bytes(field string) []byte {
74-
f := c.Obj.Lookup(field)
74+
f := c.Obj.LookupPath(cue.MakePath(cue.Str(field)))
7575
value, err := f.Bytes()
7676
if err != nil {
7777
c.addErr(f, err, "invalid bytes argument")

internal/third_party/yaml/decode.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func (d *decoder) attachDocComments(m yaml_mark_t, pos int8, expr ast.Node) {
299299
line = c.mark.line
300300
}
301301
if len(comments) > 0 {
302-
expr.AddComment(&ast.CommentGroup{
302+
ast.AddComment(expr, &ast.CommentGroup{
303303
Doc: pos == 0 && line+1 == m.line,
304304
Position: pos,
305305
List: comments,
@@ -317,7 +317,7 @@ func (d *decoder) attachLineComment(m yaml_mark_t, pos int8, expr ast.Node) {
317317
Slash: d.pos(c.mark),
318318
Text: "//" + c.text[1:],
319319
}
320-
expr.AddComment(&ast.CommentGroup{
320+
ast.AddComment(expr, &ast.CommentGroup{
321321
Line: true,
322322
Position: pos,
323323
List: []*ast.Comment{comment},

0 commit comments

Comments
 (0)