cue: remove IsValid
semantics was way too confusing.
Use Err or Exists instead.
Change-Id: I56cdccc3bd11c4ed71d4643344c71cd326a7b84b
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3321
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/export.go b/cmd/cue/cmd/export.go
index 783c983..9924273 100644
--- a/cmd/cue/cmd/export.go
+++ b/cmd/cue/cmd/export.go
@@ -100,9 +100,6 @@
for _, inst := range instances {
root := inst.Value()
- if !root.IsValid() {
- continue
- }
switch media := flagMedia.String(cmd); media {
case "json":
err := outputJSON(cmd, w, root)
diff --git a/cmd/cue/cmd/trim.go b/cmd/cue/cmd/trim.go
index b0d22bb..2525134 100644
--- a/cmd/cue/cmd/trim.go
+++ b/cmd/cue/cmd/trim.go
@@ -322,7 +322,7 @@
for _, v := range mSplit {
// TODO: consider resolving incomplete values within the current
// scope, as we do for fields.
- if v.IsValid() {
+ if v.Exists() {
in = in.Unify(v)
}
gen = append(gen, v.Source())
diff --git a/cue/load/config.go b/cue/load/config.go
index 8b58091..41df679 100644
--- a/cue/load/config.go
+++ b/cue/load/config.go
@@ -378,7 +378,7 @@
return nil, errors.Wrapf(err, token.NoPos, "invalid cue.mod file")
}
prefix := inst.Lookup("module")
- if prefix.IsValid() {
+ if prefix.Exists() {
name, err := prefix.String()
if err != nil {
return &c, err
diff --git a/cue/load/loader_test.go b/cue/load/loader_test.go
index e9150d0..c51f55d 100644
--- a/cue/load/loader_test.go
+++ b/cue/load/loader_test.go
@@ -275,7 +275,7 @@
c := &Config{
Overlay: map[string]Source{
// Not necessary, but nice to add.
- abs("cue.mod"): FromString(`module: acme.com`),
+ abs("cue.mod"): FromString(`module: "acme.com"`),
abs("dir/top.cue"): FromBytes([]byte(`
package top
diff --git a/cue/types.go b/cue/types.go
index 52be547..3494377 100644
--- a/cue/types.go
+++ b/cue/types.go
@@ -870,16 +870,6 @@
return isIncomplete(x)
}
-// IsValid reports whether this value is defined and evaluates to something
-// other than an error.
-func (v Value) IsValid() bool {
- if v.path == nil || v.path.cache == nil {
- return false
- }
- k := v.eval(v.ctx()).kind()
- return k != bottomKind && !v.IsIncomplete()
-}
-
// Exists reports whether this value existed in the configuration.
func (v Value) Exists() bool {
if v.path == nil {
diff --git a/cue/types_test.go b/cue/types_test.go
index 02ee635..a733022 100644
--- a/cue/types_test.go
+++ b/cue/types_test.go
@@ -197,13 +197,6 @@
if got := v.IsConcrete(); got != tc.concrete {
t.Errorf("IsConcrete: got %v; want %v", got, tc.concrete)
}
- invalid := tc.kind == BottomKind
- if got := v.IsValid(); got != !invalid {
- t.Errorf("IsValid: got %v; want %v", got, !invalid)
- }
- // if got, want := v.Pos(), tc.pos+1; got != want {
- // t.Errorf("pos: got %v; want %v", got, want)
- // }
})
}
}
diff --git a/pkg/tool/exec/exec.go b/pkg/tool/exec/exec.go
index ad288d1..f4b19b2 100644
--- a/pkg/tool/exec/exec.go
+++ b/pkg/tool/exec/exec.go
@@ -78,7 +78,7 @@
cmd := exec.CommandContext(ctx.Context, bin, args...)
- if v := v.Lookup("stdin"); v.IsValid() {
+ if v := v.Lookup("stdin"); v.Exists() {
if cmd.Stdin, err = v.Reader(); err != nil {
return nil, fmt.Errorf("cue: %v", err)
}