cmd/cue/cmd: fix: disable elimination of slices

It seems that slices commonly used in JSON query
languages. For compatibility, it may be good to keep
this construct. The semantics would likely have to be
adopted to be Python style.

Change-Id: I17a9e7a468e03aee90b118868eb66bbf8712c866
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3764
Reviewed-by: roger peppe <rogpeppe@gmail.com>
diff --git a/cmd/cue/cmd/fix.go b/cmd/cue/cmd/fix.go
index 5406384..320b7f9 100644
--- a/cmd/cue/cmd/fix.go
+++ b/cmd/cue/cmd/fix.go
@@ -96,38 +96,40 @@
 		return true
 	}, nil).(*ast.File)
 
+	// TODO: we are probably reintroducing slices. Disable for now.
+	//
 	// Rewrite slice expression.
-	f = astutil.Apply(f, func(c astutil.Cursor) bool {
-		n := c.Node()
-		getVal := func(n ast.Expr) ast.Expr {
-			if n == nil {
-				return nil
-			}
-			if id, ok := n.(*ast.Ident); ok && id.Name == "_" {
-				return nil
-			}
-			return n
-		}
-		switch x := n.(type) {
-		case *ast.SliceExpr:
-			ast.SetRelPos(x.X, token.NoRelPos)
+	// f = astutil.Apply(f, func(c astutil.Cursor) bool {
+	// 	n := c.Node()
+	// 	getVal := func(n ast.Expr) ast.Expr {
+	// 		if n == nil {
+	// 			return nil
+	// 		}
+	// 		if id, ok := n.(*ast.Ident); ok && id.Name == "_" {
+	// 			return nil
+	// 		}
+	// 		return n
+	// 	}
+	// 	switch x := n.(type) {
+	// 	case *ast.SliceExpr:
+	// 		ast.SetRelPos(x.X, token.NoRelPos)
 
-			lo := getVal(x.Low)
-			hi := getVal(x.High)
-			if lo == nil { // a[:j]
-				lo = mustParseExpr("0")
-				astutil.CopyMeta(lo, x.Low)
-			}
-			if hi == nil { // a[i:]
-				hi = ast.NewCall(ast.NewIdent("len"), x.X)
-				astutil.CopyMeta(lo, x.High)
-			}
-			if pkg := c.Import("list"); pkg != nil {
-				c.Replace(ast.NewCall(ast.NewSel(pkg, "Slice"), x.X, lo, hi))
-			}
-		}
-		return true
-	}, nil).(*ast.File)
+	// 		lo := getVal(x.Low)
+	// 		hi := getVal(x.High)
+	// 		if lo == nil { // a[:j]
+	// 			lo = mustParseExpr("0")
+	// 			astutil.CopyMeta(lo, x.Low)
+	// 		}
+	// 		if hi == nil { // a[i:]
+	// 			hi = ast.NewCall(ast.NewIdent("len"), x.X)
+	// 			astutil.CopyMeta(lo, x.High)
+	// 		}
+	// 		if pkg := c.Import("list"); pkg != nil {
+	// 			c.Replace(ast.NewCall(ast.NewSel(pkg, "Slice"), x.X, lo, hi))
+	// 		}
+	// 	}
+	// 	return true
+	// }, nil).(*ast.File)
 
 	return f
 }
diff --git a/cmd/cue/cmd/fix_test.go b/cmd/cue/cmd/fix_test.go
index cb70740..290b326 100644
--- a/cmd/cue/cmd/fix_test.go
+++ b/cmd/cue/cmd/fix_test.go
@@ -107,49 +107,49 @@
 // f
 a: 3 + 5
 `,
-	}, {
-		name: "slice",
-		in: `package foo
+		// 	}, {
+		// 		name: "slice",
+		// 		in: `package foo
 
-// keep comment
-l[3:4] // and this one
+		// // keep comment
+		// l[3:4] // and this one
 
-a: len(l[3:4])
-b: len(l[a:_])
-c: len(l[_:x])
-d: len(l[_:_])
-`,
-		out: `package foo
+		// a: len(l[3:4])
+		// b: len(l[a:_])
+		// c: len(l[_:x])
+		// d: len(l[_:_])
+		// `,
+		// 		out: `package foo
 
-import list6c6973 "list"
+		// import list6c6973 "list"
 
-// keep comment
-list6c6973.Slice(l, 3, 4)// and this one
+		// // keep comment
+		// list6c6973.Slice(l, 3, 4)// and this one
 
-a: len(list6c6973.Slice(l, 3, 4))
-b: len(list6c6973.Slice(l, a, len(l)))
-c: len(list6c6973.Slice(l, 0, x))
-d: len(list6c6973.Slice(l, 0, len(l)))
-`,
-	}, {
-		name: "slice2",
-		in: `package foo
+		// a: len(list6c6973.Slice(l, 3, 4))
+		// b: len(list6c6973.Slice(l, a, len(l)))
+		// c: len(list6c6973.Slice(l, 0, x))
+		// d: len(list6c6973.Slice(l, 0, len(l)))
+		// `,
+		// 	}, {
+		// 		name: "slice2",
+		// 		in: `package foo
 
-import "list"
+		// import "list"
 
-a: list.Contains("foo")
-b: len(l[_:_])
-`,
-		out: `package foo
+		// a: list.Contains("foo")
+		// b: len(l[_:_])
+		// `,
+		// 		out: `package foo
 
-import (
-	"list"
-	list6c6973 "list"
-)
+		// import (
+		// 	"list"
+		// 	list6c6973 "list"
+		// )
 
-a: list.Contains("foo")
-b: len(list6c6973.Slice(l, 0, len(l)))
-`,
+		// a: list.Contains("foo")
+		// b: len(list6c6973.Slice(l, 0, len(l)))
+		// `,
 	}}
 	for _, tc := range testCases {
 		t.Run(tc.name, func(t *testing.T) {