diff --git a/cue/instance.go b/cue/instance.go index cea6ffc33a6..35b713390da 100644 --- a/cue/instance.go +++ b/cue/instance.go @@ -165,17 +165,6 @@ func (inst *Instance) setListOrError(err errors.Error) { inst.Err = errors.Append(inst.Err, err) } -func (inst *Instance) setError(err errors.Error) { - inst.Incomplete = true - inst.Err = errors.Append(inst.Err, err) -} - -func (inst *Instance) eval(ctx *adt.OpContext) adt.Value { - // TODO: remove manifest here? - v := manifest(ctx, inst.root) - return v -} - // ID returns the package identifier that uniquely qualifies module and // package name. func (inst *Instance) ID() string { diff --git a/cue/types.go b/cue/types.go index d2704b2e5d6..7f246a81cff 100644 --- a/cue/types.go +++ b/cue/types.go @@ -719,133 +719,6 @@ func (v Value) Default() (Value, bool) { return v, false } return makeValue(v.idx, d, v.parent_), true - - // d, ok := v.v.Value.(*adt.Disjunction) - // if !ok { - // return v, false - // } - - // var w *adt.Vertex - - // switch d.NumDefaults { - // case 0: - // return v, false - - // case 1: - // w = d.Values[0] - - // default: - // x := *v.v - // x.Value = &adt.Disjunction{ - // Src: d.Src, - // Values: d.Values[:d.NumDefaults], - // NumDefaults: 0, - // } - // w = &x - // } - - // w.Conjuncts = nil - // for _, c := range v.v.Conjuncts { - // // TODO: preserve field information. - // expr, _ := stripNonDefaults(c.Expr()) - // w.AddConjunct(adt.MakeConjunct(c.Env, expr)) - // } - - // return makeValue(v.idx, w), true - - // if !stripped { - // return v, false - // } - - // n := *v.v - // n.Conjuncts = conjuncts - // return Value{v.idx, &n}, true - - // isDefault := false - // for _, c := range v.v.Conjuncts { - // if hasDisjunction(c.Expr()) { - // isDefault = true - // break - // } - // } - - // if !isDefault { - // return v, false - // } - - // TODO: record expanded disjunctions in output. - // - Rename Disjunction to DisjunctionExpr - // - Introduce Disjuncts with Values. - // - In Expr introduce Star - // - Don't pick default by default? - - // Evaluate the value. - // x := eval.FinalizeValue(v.idx.Runtime, v.v) - // if b, _ := x.Value.(*adt.Bottom); b != nil { // && b.IsIncomplete() { - // return v, false - // } - // // Finalize and return here. - // return Value{v.idx, x}, isDefault -} - -// TODO: this should go: record preexpanded disjunctions in Vertex. -func hasDisjunction(expr adt.Expr) bool { - switch x := expr.(type) { - case *adt.DisjunctionExpr: - return true - case *adt.Conjunction: - for _, v := range x.Values { - if hasDisjunction(v) { - return true - } - } - case *adt.BinaryExpr: - switch x.Op { - case adt.OrOp: - return true - case adt.AndOp: - return hasDisjunction(x.X) || hasDisjunction(x.Y) - } - } - return false -} - -// TODO: this should go: record preexpanded disjunctions in Vertex. -func stripNonDefaults(expr adt.Expr) (r adt.Expr, stripped bool) { - switch x := expr.(type) { - case *adt.DisjunctionExpr: - if !x.HasDefaults { - return x, false - } - d := *x - d.Values = []adt.Disjunct{} - for _, v := range x.Values { - if v.Default { - d.Values = append(d.Values, v) - } - } - if len(d.Values) == 1 { - return d.Values[0].Val, true - } - return &d, true - - case *adt.BinaryExpr: - if x.Op != adt.AndOp { - return x, false - } - a, sa := stripNonDefaults(x.X) - b, sb := stripNonDefaults(x.Y) - if sa || sb { - bin := *x - bin.X = a - bin.Y = b - return &bin, true - } - return x, false - - default: - return x, false - } } // Label reports he label used to obtain this value from the enclosing struct. diff --git a/cue/types_test.go b/cue/types_test.go index 76c16da754d..18f89c4e78d 100644 --- a/cue/types_test.go +++ b/cue/types_test.go @@ -3324,10 +3324,12 @@ func TestPathCorrection(t *testing.T) { if !i.Next() { t.Fatal("no fields") } - // Locate b + // Locate b, the second field i, _ = i.Value().Fields(cue.Definitions(true), cue.Optional(true)) - if !(i.Next() && i.Next()) { - t.Fatal("no fields") + for range 2 { + if !i.Next() { + t.Fatal("no fields") + } } v := i.Value() return v