21

all: gofmt -w -r 'interface{} -> any' src · golang/go@2580d0e · GitHub

 2 years ago
source link: https://github.com/golang/go/commit/2580d0e08d5e9f979b943758d3c49877fb2324cb
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

gofmt -w -r 'interface{} -> any' src · golang/go@2580d0e · GitHub

Permalink

Browse files

all: gofmt -w -r 'interface{} -> any' src
And then revert the bootstrap cmd directories and certain testdata.
And adjust tests as needed.

Not reverting the changes in std that are bootstrapped,
because some of those changes would appear in API docs,
and we want to use any consistently.
Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories
when preparing the bootstrap copy.

A few files changed as a result of running gofmt -w
not because of interface{} -> any but because they
hadn't been updated for the new //go:build lines.

Fixes #49884.

Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09
Reviewed-on: https://go-review.googlesource.com/c/go/+/368254
Trust: Russ Cox <[email protected]>
Run-TryBot: Russ Cox <[email protected]>
Reviewed-by: Robert Griesemer <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>

rsc

committed yesterday

1 parent 083ef54 commit 2580d0e08d5e9f979b943758d3c49877fb2324cb
Showing 445 changed files with 1,906 additions and 1,875 deletions.

@@ -538,7 +538,7 @@ type headerFileInfo struct {

func (fi headerFileInfo) Size() int64 { return fi.h.Size }

func (fi headerFileInfo) IsDir() bool { return fi.Mode().IsDir() }

func (fi headerFileInfo) ModTime() time.Time { return fi.h.ModTime }

func (fi headerFileInfo) Sys() interface{} { return fi.h }

func (fi headerFileInfo) Sys() any { return fi.h }

// Name returns the base name of the file.

func (fi headerFileInfo) Name() string {

@@ -1363,7 +1363,7 @@ func TestFileReader(t *testing.T) {

wantLCnt int64

wantPCnt int64

}

testFnc interface{} // testRead | testWriteTo | testRemaining

testFnc any // testRead | testWriteTo | testRemaining

)

type (

@@ -1376,7 +1376,7 @@ func TestFileReader(t *testing.T) {

spd sparseDatas

size int64

}

fileMaker interface{} // makeReg | makeSparse

fileMaker any // makeReg | makeSparse

)

vectors := []struct {

@@ -23,7 +23,7 @@ import (

type testError struct{ error }

type fileOps []interface{} // []T where T is (string | int64)

type fileOps []any // []T where T is (string | int64)

// testFile is an io.ReadWriteSeeker where the IO operations performed

// on it must match the list of operations in ops.

@@ -67,7 +67,7 @@ func TestWriter(t *testing.T) {

testClose struct { // Close() == wantErr

wantErr error

}

testFnc interface{} // testHeader | testWrite | testReadFrom | testClose

testFnc any // testHeader | testWrite | testReadFrom | testClose

)

vectors := []struct {

@@ -1031,7 +1031,7 @@ func TestFileWriter(t *testing.T) {

wantLCnt int64

wantPCnt int64

}

testFnc interface{} // testWrite | testReadFrom | testRemaining

testFnc any // testWrite | testReadFrom | testRemaining

)

type (

@@ -1044,7 +1044,7 @@ func TestFileWriter(t *testing.T) {

sph sparseHoles

size int64

}

fileMaker interface{} // makeReg | makeSparse

fileMaker any // makeReg | makeSparse

)

vectors := []struct {

@@ -670,7 +670,7 @@ func (f *fileListEntry) Size() int64 { return 0 }

func (f *fileListEntry) Mode() fs.FileMode { return fs.ModeDir | 0555 }

func (f *fileListEntry) Type() fs.FileMode { return fs.ModeDir }

func (f *fileListEntry) IsDir() bool { return true }

func (f *fileListEntry) Sys() interface{} { return nil }

func (f *fileListEntry) Sys() any { return nil }

func (f *fileListEntry) ModTime() time.Time {

if f.file == nil {

@@ -163,7 +163,7 @@ func (fi headerFileInfo) ModTime() time.Time {

}

func (fi headerFileInfo) Mode() fs.FileMode { return fi.fh.Mode() }

func (fi headerFileInfo) Type() fs.FileMode { return fi.fh.Mode().Type() }

func (fi headerFileInfo) Sys() interface{} { return fi.fh }

func (fi headerFileInfo) Sys() any { return fi.fh }

func (fi headerFileInfo) Info() (fs.FileInfo, error) { return fi, nil }

@@ -239,7 +239,7 @@ func close(c chan<- Type)

// that point, the program is terminated with a non-zero exit code. This

// termination sequence is called panicking and can be controlled by the

// built-in function recover.

func panic(v interface{})

func panic(v any)

// The recover built-in function allows a program to manage behavior of a

// panicking goroutine. Executing a call to recover inside a deferred

@@ -250,7 +250,7 @@ func panic(v interface{})

// panicking, or if the argument supplied to panic was nil, recover returns

// nil. Thus the return value from recover reports whether the goroutine is

// panicking.

func recover() interface{}

func recover() any

// The print built-in function formats its arguments in an

// implementation-specific way and writes the result to standard error.

@@ -76,7 +76,7 @@ func TestReaderAt(t *testing.T) {

off int64

n int

want string

wanterr interface{}

wanterr any

}{

{0, 10, "0123456789", nil},

{1, 10, "123456789", io.EOF},

@@ -1071,7 +1071,7 @@ func (w *Walker) emitMethod(m *types.Selection) {

w.emitf("method (%s%s) %s%s", w.typeString(recv), tps, m.Obj().Name(), w.signatureString(sig))

}

func (w *Walker) emitf(format string, args ...interface{}) {

func (w *Walker) emitf(format string, args ...any) {

f := strings.Join(w.scope, ", ") + ", " + fmt.Sprintf(format, args...)

if strings.Contains(f, "\n") {

panic("feature contains newlines: " + f)

@@ -1,3 +1,4 @@

//go:build !amd64

// +build !amd64

package p

@@ -197,7 +197,7 @@ var m map[string]int

var chanVar chan int

var ifaceVar interface{} = 5

var ifaceVar any = 5

var assertVar = ifaceVar.(int)

@@ -4,12 +4,12 @@

package p4

type Pair[T1 interface { M() }, T2 ~int] struct {

type Pair[T1 interface{ M() }, T2 ~int] struct {

f1 T1

f2 T2

}

func NewPair[T1 interface { M() }, T2 ~int](v1 T1, v2 T2) Pair[T1, T2] {

func NewPair[T1 interface{ M() }, T2 ~int](v1 T1, v2 T2) Pair[T1, T2] {

return Pair[T1, T2]{f1: v1, f2: v2}

}

@@ -258,7 +258,7 @@ var importedObjectTests = []struct {

{"go/internal/gcimporter.FindPkg", "func FindPkg(path string, srcDir string) (filename string, id string)"},

// interfaces

{"context.Context", "type Context interface{Deadline() (deadline time.Time, ok bool); Done() <-chan struct{}; Err() error; Value(key interface{}) interface{}}"},

{"context.Context", "type Context interface{Deadline() (deadline time.Time, ok bool); Done() <-chan struct{}; Err() error; Value(key any) any}"},

{"crypto.Decrypter", "type Decrypter interface{Decrypt(rand io.Reader, msg []byte, opts DecrypterOpts) (plaintext []byte, err error); Public() PublicKey}"},

{"encoding.BinaryMarshaler", "type BinaryMarshaler interface{MarshalBinary() (data []byte, err error)}"},

{"io.Reader", "type Reader interface{Read(p []byte) (n int, err error)}"},

@@ -151,7 +151,7 @@ func testSwitch() {

}

func testTypeSwitch() {

var x = []interface{}{1, 2.0, "hi"}

var x = []any{1, 2.0, "hi"}

for _, v := range x {

switch func() { check(LINE, 3) }(); v.(type) {

case int:

@@ -215,7 +215,7 @@ func testEmptySwitches() {

switch 3 {

}

check(LINE, 1)

switch i := (interface{})(3).(int); i {

switch i := (any)(3).(int); i {

}

check(LINE, 1)

c := make(chan int)

@@ -15,6 +15,7 @@ import (

"fmt"

"os"

"path/filepath"

"regexp"

"runtime"

"strings"

)

@@ -288,7 +289,11 @@ func rewriteBlock%s(b *Block) bool { panic("unused during bootstrap") }

}

func bootstrapFixImports(srcFile string) string {

lines := strings.SplitAfter(readfile(srcFile), "\n")

text := readfile(srcFile)

if !strings.Contains(srcFile, "/cmd/") && !strings.Contains(srcFile, `\cmd\`) {

text = regexp.MustCompile(`\bany\b`).ReplaceAllString(text, "interface{}")

}

lines := strings.SplitAfter(text, "\n")

inBlock := false

for i, line := range lines {

if strings.HasPrefix(line, "import (") {

@@ -122,7 +122,7 @@ func trim(path, prefix string) (string, bool) {

// main do function, so it doesn't cause an exit. Allows testing to work

// without running a subprocess. The log prefix will be added when

// logged in main; it is not added here.

func (pkg *Package) Fatalf(format string, args ...interface{}) {

func (pkg *Package) Fatalf(format string, args ...any) {

panic(PackageError(fmt.Sprintf(format, args...)))

}

@@ -209,7 +209,7 @@ func parsePackage(writer io.Writer, pkg *build.Package, userPath string) *Packag

return p

}

func (pkg *Package) Printf(format string, args ...interface{}) {

func (pkg *Package) Printf(format string, args ...any) {

fmt.Fprintf(&pkg.buf, format, args...)

}

@@ -235,7 +235,7 @@ func (pkg *Package) newlines(n int) {

// clears the stuff we don't want to print anyway. It's a bit of a magic trick.

func (pkg *Package) emit(comment string, node ast.Node) {

if node != nil {

var arg interface{} = node

var arg any = node

if showSrc {

// Need an extra little dance to get internal comments to appear.

arg = &printer.CommentedNode{

@@ -1,3 +1,4 @@

//go:build ignore

// +build ignore

// Ignored package

@@ -45,8 +45,8 @@ func typefix(f *ast.File, badType func(string) bool) bool {

// step 1: Find all the nils with the offending types.

// Compute their replacement.

badNils := map[interface{}]ast.Expr{}

walk(f, func(n interface{}) {

badNils := map[any]ast.Expr{}

walk(f, func(n any) {

if i, ok := n.(*ast.Ident); ok && i.Name == "nil" && badType(typeof[n]) {

badNils[n] = &ast.BasicLit{ValuePos: i.NamePos, Kind: token.INT, Value: "0"}

}

@@ -58,7 +58,7 @@ func typefix(f *ast.File, badType func(string) bool) bool {

if len(badNils) > 0 {

exprType := reflect.TypeOf((*ast.Expr)(nil)).Elem()

exprSliceType := reflect.TypeOf(([]ast.Expr)(nil))

walk(f, func(n interface{}) {

walk(f, func(n any) {

if n == nil {

return

}

@@ -99,7 +99,7 @@ func typefix(f *ast.File, badType func(string) bool) bool {

// Now we need unsafe.Pointer as an intermediate cast.

// (*unsafe.Pointer)(x) where x is type *bad -> (*unsafe.Pointer)(unsafe.Pointer(x))

// (*bad.type)(x) where x is type *unsafe.Pointer -> (*bad.type)(unsafe.Pointer(x))

walk(f, func(n interface{}) {

walk(f, func(n any) {

if n == nil {

return

}

@@ -43,15 +43,15 @@ func register(f fix) {

// walk traverses the AST x, calling visit(y) for each node y in the tree but

// also with a pointer to each ast.Expr, ast.Stmt, and *ast.BlockStmt,

// in a bottom-up traversal.

func walk(x interface{}, visit func(interface{})) {

func walk(x any, visit func(any)) {

walkBeforeAfter(x, nop, visit)

}

func nop(interface{}) {}

func nop(any) {}

// walkBeforeAfter is like walk but calls before(x) before traversing

// x's children and after(x) afterward.

func walkBeforeAfter(x interface{}, before, after func(interface{})) {

func walkBeforeAfter(x any, before, after func(any)) {

before(x)

switch n := x.(type) {

@@ -390,7 +390,7 @@ func renameTop(f *ast.File, old, new string) bool {

// Rename top-level old to new, both unresolved names

// (probably defined in another file) and names that resolve

// to a declaration we renamed.

walk(f, func(n interface{}) {

walk(f, func(n any) {

id, ok := n.(*ast.Ident)

if ok && isTopName(id, old) {

id.Name = new

@@ -36,7 +36,7 @@ func fixGoExact(f *ast.File) bool {

// This one is harder because the import name changes.

// First find the import spec.

var importSpec *ast.ImportSpec

walk(f, func(n interface{}) {

walk(f, func(n any) {

if importSpec != nil {

return

}

@@ -245,7 +245,7 @@ func processFile(filename string, useStdin bool) error {

return os.WriteFile(f.Name(), newSrc, 0)

}

func gofmt(n interface{}) string {

func gofmt(n any) string {

var gofmtBuf bytes.Buffer

if err := format.Node(&gofmtBuf, fset, n); err != nil {

return "<" + err.Error() + ">"

@@ -26,7 +26,7 @@ func netipv6zone(f *ast.File) bool {

}

fixed := false

walk(f, func(n interface{}) {

walk(f, func(n any) {

cl, ok := n.(*ast.CompositeLit)

if !ok {

return

@@ -23,7 +23,7 @@ func printerconfig(f *ast.File) bool {

}

fixed := false

walk(f, func(n interface{}) {

walk(f, func(n any) {

cl, ok := n.(*ast.CompositeLit)

if !ok {

return

@@ -142,9 +142,9 @@ func (typ *Type) dot(cfg *TypeConfig, name string) string {

// typeof maps AST nodes to type information in gofmt string form.

// assign maps type strings to lists of expressions that were assigned

// to values of another type that were assigned to that type.

func typecheck(cfg *TypeConfig, f *ast.File) (typeof map[interface{}]string, assign map[string][]interface{}) {

typeof = make(map[interface{}]string)

assign = make(map[string][]interface{})

func typecheck(cfg *TypeConfig, f *ast.File) (typeof map[any]string, assign map[string][]any) {

typeof = make(map[any]string)

assign = make(map[string][]any)

cfg1 := &TypeConfig{}

*cfg1 = *cfg // make copy so we can add locally

copied := false

@@ -296,7 +296,7 @@ func makeExprList(a []*ast.Ident) []ast.Expr {

// Typecheck1 is the recursive form of typecheck.

// It is like typecheck but adds to the information in typeof

// instead of allocating a new map.

func typecheck1(cfg *TypeConfig, f interface{}, typeof map[interface{}]string, assign map[string][]interface{}) {

func typecheck1(cfg *TypeConfig, f any, typeof map[any]string, assign map[string][]any) {

// set sets the type of n to typ.

// If isDecl is true, n is being declared.

set := func(n ast.Expr, typ string, isDecl bool) {

@@ -368,7 +368,7 @@ func typecheck1(cfg *TypeConfig, f interface{}, typeof map[interface{}]string, a

// the curfn stack.

var curfn []*ast.FuncType

before := func(n interface{}) {

before := func(n any) {

// push function type on stack

switch n := n.(type) {

case *ast.FuncDecl:

@@ -379,7 +379,7 @@ func typecheck1(cfg *TypeConfig, f interface{}, typeof map[interface{}]string, a

}

// After is the real type checker.

after := func(n interface{}) {

after := func(n any) {

if n == nil {

return

}

@@ -117,12 +117,12 @@ func Exit() {

os.Exit(exitStatus)

}

func Fatalf(format string, args ...interface{}) {

func Fatalf(format string, args ...any) {

Errorf(format, args...)

Exit()

}

func Errorf(format string, args ...interface{}) {

func Errorf(format string, args ...any) {

log.Printf(format, args...)

SetExitStatus(1)

}

@@ -151,7 +151,7 @@ func GetExitStatus() int {

// Run runs the command, with stdout and stderr

// connected to the go command's own stdout and stderr.

// If the command fails, Run reports the error using Errorf.

func Run(cmdargs ...interface{}) {

func Run(cmdargs ...any) {

cmdline := str.StringList(cmdargs...)

if cfg.BuildN || cfg.BuildX {

fmt.Printf("%s\n", strings.Join(cmdline, " "))

@@ -92,7 +92,7 @@ func ParseOne(fs *flag.FlagSet, args []string) (f *flag.Flag, remainingArgs []st

// Use fs.Set instead of f.Value.Set below so that any subsequent call to

// fs.Visit will correctly visit the flags that have been set.

failf := func(format string, a ...interface{}) (*flag.Flag, []string, error) {

failf := func(format string, a ...any) (*flag.Flag, []string, error) {

return f, args, fmt.Errorf(format, a...)

}

Loading

0 comments on commit 2580d0e

Please sign in to comment.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK