Skip to content

Commit 537f744

Browse files
committed
cue: resolve a few staticcheck warnings
Instance's setError and eval methods are unexported and unused. Moreover, Instance itself has been deprecated for years. hasDisjunction and stripNonDefaults, as well as their uses in the commented-out bit of code in Value.Default, have been unused for at least four years. They are still present in the git history if needed, but clearly they are not needed now and have not actually been for a long time already. Finally, rewrite the way a test advances an iterator twice so that it doesn't make staticcheck think that we mistakenly checked the same condition twice, which is often due to human error. Updates #3335. Signed-off-by: Daniel Martí <[email protected]> Change-Id: If6608b5d9d1076316e3c03e530b6b6577a157605 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202602 Reviewed-by: Roger Peppe <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent d9fda8c commit 537f744

File tree

3 files changed

+5
-141
lines changed

3 files changed

+5
-141
lines changed

cue/instance.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,6 @@ func (inst *Instance) setListOrError(err errors.Error) {
165165
inst.Err = errors.Append(inst.Err, err)
166166
}
167167

168-
func (inst *Instance) setError(err errors.Error) {
169-
inst.Incomplete = true
170-
inst.Err = errors.Append(inst.Err, err)
171-
}
172-
173-
func (inst *Instance) eval(ctx *adt.OpContext) adt.Value {
174-
// TODO: remove manifest here?
175-
v := manifest(ctx, inst.root)
176-
return v
177-
}
178-
179168
// ID returns the package identifier that uniquely qualifies module and
180169
// package name.
181170
func (inst *Instance) ID() string {

cue/types.go

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -719,133 +719,6 @@ func (v Value) Default() (Value, bool) {
719719
return v, false
720720
}
721721
return makeValue(v.idx, d, v.parent_), true
722-
723-
// d, ok := v.v.Value.(*adt.Disjunction)
724-
// if !ok {
725-
// return v, false
726-
// }
727-
728-
// var w *adt.Vertex
729-
730-
// switch d.NumDefaults {
731-
// case 0:
732-
// return v, false
733-
734-
// case 1:
735-
// w = d.Values[0]
736-
737-
// default:
738-
// x := *v.v
739-
// x.Value = &adt.Disjunction{
740-
// Src: d.Src,
741-
// Values: d.Values[:d.NumDefaults],
742-
// NumDefaults: 0,
743-
// }
744-
// w = &x
745-
// }
746-
747-
// w.Conjuncts = nil
748-
// for _, c := range v.v.Conjuncts {
749-
// // TODO: preserve field information.
750-
// expr, _ := stripNonDefaults(c.Expr())
751-
// w.AddConjunct(adt.MakeConjunct(c.Env, expr))
752-
// }
753-
754-
// return makeValue(v.idx, w), true
755-
756-
// if !stripped {
757-
// return v, false
758-
// }
759-
760-
// n := *v.v
761-
// n.Conjuncts = conjuncts
762-
// return Value{v.idx, &n}, true
763-
764-
// isDefault := false
765-
// for _, c := range v.v.Conjuncts {
766-
// if hasDisjunction(c.Expr()) {
767-
// isDefault = true
768-
// break
769-
// }
770-
// }
771-
772-
// if !isDefault {
773-
// return v, false
774-
// }
775-
776-
// TODO: record expanded disjunctions in output.
777-
// - Rename Disjunction to DisjunctionExpr
778-
// - Introduce Disjuncts with Values.
779-
// - In Expr introduce Star
780-
// - Don't pick default by default?
781-
782-
// Evaluate the value.
783-
// x := eval.FinalizeValue(v.idx.Runtime, v.v)
784-
// if b, _ := x.Value.(*adt.Bottom); b != nil { // && b.IsIncomplete() {
785-
// return v, false
786-
// }
787-
// // Finalize and return here.
788-
// return Value{v.idx, x}, isDefault
789-
}
790-
791-
// TODO: this should go: record preexpanded disjunctions in Vertex.
792-
func hasDisjunction(expr adt.Expr) bool {
793-
switch x := expr.(type) {
794-
case *adt.DisjunctionExpr:
795-
return true
796-
case *adt.Conjunction:
797-
for _, v := range x.Values {
798-
if hasDisjunction(v) {
799-
return true
800-
}
801-
}
802-
case *adt.BinaryExpr:
803-
switch x.Op {
804-
case adt.OrOp:
805-
return true
806-
case adt.AndOp:
807-
return hasDisjunction(x.X) || hasDisjunction(x.Y)
808-
}
809-
}
810-
return false
811-
}
812-
813-
// TODO: this should go: record preexpanded disjunctions in Vertex.
814-
func stripNonDefaults(expr adt.Expr) (r adt.Expr, stripped bool) {
815-
switch x := expr.(type) {
816-
case *adt.DisjunctionExpr:
817-
if !x.HasDefaults {
818-
return x, false
819-
}
820-
d := *x
821-
d.Values = []adt.Disjunct{}
822-
for _, v := range x.Values {
823-
if v.Default {
824-
d.Values = append(d.Values, v)
825-
}
826-
}
827-
if len(d.Values) == 1 {
828-
return d.Values[0].Val, true
829-
}
830-
return &d, true
831-
832-
case *adt.BinaryExpr:
833-
if x.Op != adt.AndOp {
834-
return x, false
835-
}
836-
a, sa := stripNonDefaults(x.X)
837-
b, sb := stripNonDefaults(x.Y)
838-
if sa || sb {
839-
bin := *x
840-
bin.X = a
841-
bin.Y = b
842-
return &bin, true
843-
}
844-
return x, false
845-
846-
default:
847-
return x, false
848-
}
849722
}
850723

851724
// Label reports he label used to obtain this value from the enclosing struct.

cue/types_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,10 +3324,12 @@ func TestPathCorrection(t *testing.T) {
33243324
if !i.Next() {
33253325
t.Fatal("no fields")
33263326
}
3327-
// Locate b
3327+
// Locate b, the second field
33283328
i, _ = i.Value().Fields(cue.Definitions(true), cue.Optional(true))
3329-
if !(i.Next() && i.Next()) {
3330-
t.Fatal("no fields")
3329+
for range 2 {
3330+
if !i.Next() {
3331+
t.Fatal("no fields")
3332+
}
33313333
}
33323334
v := i.Value()
33333335
return v

0 commit comments

Comments
 (0)