Skip to content

Commit ed5cdf0

Browse files
committed
cue: more path cleanup
Change-Id: I4bb273b019e40b0c7b6dd838b7cfb7def6ad2627 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9573 Reviewed-by: CUE cueckoo <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent c365513 commit ed5cdf0

File tree

4 files changed

+20
-25
lines changed

4 files changed

+20
-25
lines changed

cue/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (e *valueError) Path() (a []string) {
8787
return a
8888
}
8989
}
90-
return e.v.appendPath(nil)
90+
return pathToStrings(e.v.Path())
9191
}
9292

9393
var errNotExists = &adt.Bottom{

cue/path.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ func MakePath(selectors ...Selector) Path {
106106
return Path{path: selectors}
107107
}
108108

109+
// pathToString is a utility function for creating debugging info.
110+
func pathToStrings(p Path) (a []string) {
111+
for _, sel := range p.Selectors() {
112+
a = append(a, sel.String())
113+
}
114+
return a
115+
}
116+
109117
// ParsePath parses a CUE expression into a Path. Any error resulting from
110118
// this conversion can be obtained by calling Err on the result.
111119
//

cue/types.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ import (
2121
"io"
2222
"math"
2323
"math/big"
24-
"strconv"
2524
"strings"
2625

2726
"github.com/cockroachdb/apd/v2"
2827

2928
"cuelang.org/go/cue/ast"
3029
"cuelang.org/go/cue/ast/astutil"
3130
"cuelang.org/go/cue/errors"
32-
"cuelang.org/go/cue/literal"
3331
"cuelang.org/go/cue/token"
3432
"cuelang.org/go/internal"
3533
"cuelang.org/go/internal/core/adt"
@@ -551,27 +549,6 @@ func (v Value) Float64() (float64, error) {
551549
return f, nil
552550
}
553551

554-
func (v Value) appendPath(a []string) []string {
555-
for _, f := range v.v.Path() {
556-
switch f.Typ() {
557-
case adt.IntLabel:
558-
a = append(a, strconv.FormatInt(int64(f.Index()), 10))
559-
560-
case adt.StringLabel:
561-
label := v.idx.LabelStr(f)
562-
if !f.IsDef() && !f.IsHidden() {
563-
if !ast.IsValidIdent(label) {
564-
label = literal.String.Quote(label)
565-
}
566-
}
567-
a = append(a, label)
568-
default:
569-
a = append(a, f.SelectorString(v.idx))
570-
}
571-
}
572-
return a
573-
}
574-
575552
// Value holds any value, which may be a Boolean, Error, List, Null, Number,
576553
// Struct, or String.
577554
type Value struct {

cue/types_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,7 @@ func TestPath(t *testing.T) {
22482248
v = v.Lookup(e)
22492249
}
22502250
}
2251-
got := v.appendPath(nil)
2251+
got := pathToStrings(v.Path())
22522252
if !reflect.DeepEqual(got, tc) {
22532253
t.Errorf("got %v; want %v", got, tc)
22542254
}
@@ -3124,6 +3124,16 @@ func TestPathCorrection(t *testing.T) {
31243124
if gotPath != tc.want {
31253125
t.Errorf("got path %s; want %s", gotPath, tc.want)
31263126
}
3127+
3128+
x, p := v.ReferencePath()
3129+
if x.Value() != inst.Value() {
3130+
t.Error("reference not in original instance")
3131+
}
3132+
gotPath = p.String()
3133+
if gotPath != tc.want {
3134+
t.Errorf("got path %s; want %s", gotPath, tc.want)
3135+
}
3136+
31273137
})
31283138
}
31293139
}

0 commit comments

Comments
 (0)