this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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í <mvdan@mvdan.cc>
Change-Id: If6608b5d9d1076316e3c03e530b6b6577a157605
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202602
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+5 -141
-11
cue/instance.go
··· 165 165 inst.Err = errors.Append(inst.Err, err) 166 166 } 167 167 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 - 179 168 // ID returns the package identifier that uniquely qualifies module and 180 169 // package name. 181 170 func (inst *Instance) ID() string {
-127
cue/types.go
··· 719 719 return v, false 720 720 } 721 721 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 - } 849 722 } 850 723 851 724 // Label reports he label used to obtain this value from the enclosing struct.
+5 -3
cue/types_test.go
··· 3324 3324 if !i.Next() { 3325 3325 t.Fatal("no fields") 3326 3326 } 3327 - // Locate b 3327 + // Locate b, the second field 3328 3328 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 + } 3331 3333 } 3332 3334 v := i.Value() 3333 3335 return v