Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace interface{} => any #2176

Merged
merged 2 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions ast/gopq/dom.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (p astPackages) ForEach(filter func(node Node) error) error {
return nil
}

func (p astPackages) Obj() interface{} {
func (p astPackages) Obj() any {
return p
}

Expand All @@ -58,7 +58,7 @@ func (p astPackage) ForEach(filter func(node Node) error) error {
return nil
}

func (p astPackage) Obj() interface{} {
func (p astPackage) Obj() any {
return p.Package
}

Expand All @@ -78,7 +78,7 @@ func (p astFile) ForEach(filter func(node Node) error) error {
return nil
}

func (p astFile) Obj() interface{} {
func (p astFile) Obj() any {
return p.File
}

Expand All @@ -100,7 +100,7 @@ func (p *astDecl) ForEach(filter func(node Node) error) error {
return nil
}

func (p *astDecl) Obj() interface{} {
func (p *astDecl) Obj() any {
return p.Decl
}

Expand All @@ -114,7 +114,7 @@ func (p *astSpec) ForEach(filter func(node Node) error) error {
return nil
}

func (p *astSpec) Obj() interface{} {
func (p *astSpec) Obj() any {
return p.Spec
}

Expand Down Expand Up @@ -155,7 +155,7 @@ func (p *astStmt) ForEach(filter func(node Node) error) error {
return nil
}

func (p *astStmt) Obj() interface{} {
func (p *astStmt) Obj() any {
return p.Stmt
}

Expand All @@ -169,7 +169,7 @@ func (p *astExpr) ForEach(filter func(node Node) error) error {
return nil
}

func (p *astExpr) Obj() interface{} {
func (p *astExpr) Obj() any {
return p.Expr
}

Expand Down
6 changes: 3 additions & 3 deletions ast/gopq/gopq.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var (
type Node interface {
ast.Node
ForEach(filter func(node Node) error) error
Obj() interface{}
Obj() any
}

// NodeEnum - node enumerator
Expand All @@ -66,7 +66,7 @@ type NodeSet struct {
}

// FromFile calls ParseFile for a single file and returns *ast.File node set.
func FromFile(fset *token.FileSet, filename string, src interface{}, mode parser.Mode) (doc NodeSet, err error) {
func FromFile(fset *token.FileSet, filename string, src any, mode parser.Mode) (doc NodeSet, err error) {
file, err := parser.ParseFile(fset, filename, src, mode)
if err != nil {
return
Expand All @@ -77,7 +77,7 @@ func FromFile(fset *token.FileSet, filename string, src interface{}, mode parser
// FromFSFile calls ParseFSFile for a single file and returns *ast.File node set.
func FromFSFile(
fset *token.FileSet, fs fsx.FileSystem,
filename string, src interface{}, mode parser.Mode) (doc NodeSet, err error) {
filename string, src any, mode parser.Mode) (doc NodeSet, err error) {
file, err := parser.ParseFSFile(fset, fs, filename, src, mode)
if err != nil {
return
Expand Down
2 changes: 1 addition & 1 deletion ast/gopq/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func NameOf(node Node) string {
return getName(node.Obj(), false)
}

func getName(v interface{}, useEmpty bool) string {
func getName(v any, useEmpty bool) string {
switch v := v.(type) {
case *ast.FuncDecl:
return v.Name.Name
Expand Down
18 changes: 9 additions & 9 deletions ast/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ func NotNilFilter(_ string, v reflect.Value) bool {
// struct fields for which f(fieldname, fieldvalue) is true are
// printed; all others are filtered from the output. Unexported
// struct fields are never printed.
func Fprint(w io.Writer, fset *token.FileSet, x interface{}, f FieldFilter) error {
func Fprint(w io.Writer, fset *token.FileSet, x any, f FieldFilter) error {
return fprint(w, fset, x, f)
}

func fprint(w io.Writer, fset *token.FileSet, x interface{}, f FieldFilter) (err error) {
func fprint(w io.Writer, fset *token.FileSet, x any, f FieldFilter) (err error) {
// setup printer
p := printer{
output: w,
fset: fset,
filter: f,
ptrmap: make(map[interface{}]int),
ptrmap: make(map[any]int),
last: '\n', // force printing of line number on first line
}

Expand All @@ -83,18 +83,18 @@ func fprint(w io.Writer, fset *token.FileSet, x interface{}, f FieldFilter) (err

// Print prints x to standard output, skipping nil fields.
// Print(fset, x) is the same as Fprint(os.Stdout, fset, x, NotNilFilter).
func Print(fset *token.FileSet, x interface{}) error {
func Print(fset *token.FileSet, x any) error {
return Fprint(os.Stdout, fset, x, NotNilFilter)
}

type printer struct {
output io.Writer
fset *token.FileSet
filter FieldFilter
ptrmap map[interface{}]int // *T -> line number
indent int // current indentation level
last byte // the last byte processed by Write
line int // current line number
ptrmap map[any]int // *T -> line number
indent int // current indentation level
last byte // the last byte processed by Write
line int // current line number
}

var indent = []byte(". ")
Expand Down Expand Up @@ -138,7 +138,7 @@ type localError struct {
}

// printf is a convenience wrapper that takes care of print errors.
func (p *printer) printf(format string, args ...interface{}) {
func (p *printer) printf(format string, args ...any) {
if _, err := fmt.Fprintf(p, format, args...); err != nil {
panic(localError{err})
}
Expand Down
2 changes: 1 addition & 1 deletion ast/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (p *pkgBuilder) error(pos token.Pos, msg string) {
p.errors.Add(p.fset.Position(pos), msg)
}

func (p *pkgBuilder) errorf(pos token.Pos, format string, args ...interface{}) {
func (p *pkgBuilder) errorf(pos token.Pos, format string, args ...any) {
p.error(pos, fmt.Sprintf(format, args...))
}

Expand Down
8 changes: 4 additions & 4 deletions ast/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ func (s *Scope) String() string {
// Con int iota for the respective declaration
type Object struct {
Kind ObjKind
Name string // declared name
Decl interface{} // corresponding Field, XxxSpec, FuncDecl, LabeledStmt, AssignStmt, Scope; or nil
Data interface{} // object-specific data; or nil
Type interface{} // placeholder for type information; may be nil
Name string // declared name
Decl any // corresponding Field, XxxSpec, FuncDecl, LabeledStmt, AssignStmt, Scope; or nil
Data any // object-specific data; or nil
Type any // placeholder for type information; may be nil
}

// NewObj creates a new object of a given kind and name.
Expand Down
2 changes: 1 addition & 1 deletion builtin/ng/big.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"math/big"
)

func Gop_istmp(a interface{}) bool {
func Gop_istmp(a any) bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion cl/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func TestSpxRef(t *testing.T) {
spxRef(pkg, "bar")
}

func isError(e interface{}, msg string) bool {
func isError(e any, msg string) bool {
if e != nil {
if err, ok := e.(error); ok {
return err.Error() == msg
Expand Down
8 changes: 4 additions & 4 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,11 @@ func (p *pkgCtx) newCodeError(pos token.Pos, msg string) error {
return &gogen.CodeError{Fset: p.nodeInterp, Pos: pos, Msg: msg}
}

func (p *pkgCtx) newCodeErrorf(pos token.Pos, format string, args ...interface{}) error {
func (p *pkgCtx) newCodeErrorf(pos token.Pos, format string, args ...any) error {
return &gogen.CodeError{Fset: p.nodeInterp, Pos: pos, Msg: fmt.Sprintf(format, args...)}
}

func (p *pkgCtx) handleErrorf(pos token.Pos, format string, args ...interface{}) {
func (p *pkgCtx) handleErrorf(pos token.Pos, format string, args ...any) {
p.handleErr(p.newCodeErrorf(pos, format, args...))
}

Expand Down Expand Up @@ -460,12 +460,12 @@ func (p *pkgCtx) loadSymbol(name string) bool {
return false
}

func (p *pkgCtx) handleRecover(e interface{}, src ast.Node) {
func (p *pkgCtx) handleRecover(e any, src ast.Node) {
err := p.recoverErr(e, src)
p.handleErr(err)
}

func (p *pkgCtx) recoverErr(e interface{}, src ast.Node) error {
func (p *pkgCtx) recoverErr(e any, src ast.Node) error {
err, ok := e.(error)
if !ok {
if src != nil {
Expand Down
10 changes: 5 additions & 5 deletions cl/internal/spx/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Sound string
type MyGame struct {
}

func Gopt_MyGame_Main(game interface{}) {
func Gopt_MyGame_Main(game any) {
}

func (p *MyGame) Ls(n int) {}
Expand All @@ -51,20 +51,20 @@ func (p *MyGame) Broadcast__0(msg string) {
func (p *MyGame) Broadcast__1(msg string, wait bool) {
}

func (p *MyGame) Broadcast__2(msg string, data interface{}, wait bool) {
func (p *MyGame) Broadcast__2(msg string, data any, wait bool) {
}

func (p *MyGame) Play(media string, wait ...bool) {
}

func (p *MyGame) sendMessage(data interface{}) {
func (p *MyGame) sendMessage(data any) {
}

func (p *MyGame) SendMessage(data interface{}) {
func (p *MyGame) SendMessage(data any) {
p.sendMessage(data)
}

func Gopt_MyGame_Run(game interface{}, resource string) error {
func Gopt_MyGame_Run(game any, resource string) error {
return nil
}

Expand Down
26 changes: 13 additions & 13 deletions cl/internal/spx/sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (p *Entry) Vector() *pkg.Vector {
return &p.vec
}

func (p *Sprite) SetCostume(costume interface{}) {
func (p *Sprite) SetCostume(costume any) {
}

func (p *Sprite) Say(msg string, secs ...float64) {
Expand All @@ -47,38 +47,38 @@ type Mesher interface {
Name() string
}

func Gopt_Sprite_Clone__0(sprite interface{}) {
func Gopt_Sprite_Clone__0(sprite any) {
}

func Gopt_Sprite_Clone__1(sprite interface{}, data interface{}) {
func Gopt_Sprite_Clone__1(sprite any, data any) {
}

func Gopt_Sprite_OnKey__0(sprite interface{}, a string, fn func()) {
func Gopt_Sprite_OnKey__0(sprite any, a string, fn func()) {
}

func Gopt_Sprite_OnKey__1(sprite interface{}, a string, fn func(key string)) {
func Gopt_Sprite_OnKey__1(sprite any, a string, fn func(key string)) {
}

func Gopt_Sprite_OnKey__2(sprite interface{}, a []string, fn func()) {
func Gopt_Sprite_OnKey__2(sprite any, a []string, fn func()) {
}

func Gopt_Sprite_OnKey__3(sprite interface{}, a []string, fn func(key string)) {
func Gopt_Sprite_OnKey__3(sprite any, a []string, fn func(key string)) {
}

func Gopt_Sprite_OnKey__4(sprite interface{}, a []Mesher, fn func()) {
func Gopt_Sprite_OnKey__4(sprite any, a []Mesher, fn func()) {
}

func Gopt_Sprite_OnKey__5(sprite interface{}, a []Mesher, fn func(key Mesher)) {
func Gopt_Sprite_OnKey__5(sprite any, a []Mesher, fn func(key Mesher)) {
}

func Gopt_Sprite_OnKey__6(sprite interface{}, a []string, b []string, fn func(key string)) {
func Gopt_Sprite_OnKey__6(sprite any, a []string, b []string, fn func(key string)) {
}

func Gopt_Sprite_OnKey__7(sprite interface{}, a []string, b []Mesher, fn func(key string)) {
func Gopt_Sprite_OnKey__7(sprite any, a []string, b []Mesher, fn func(key string)) {
}

func Gopt_Sprite_OnKey__8(sprite interface{}, x int, y int) {
func Gopt_Sprite_OnKey__8(sprite any, x int, y int) {
}

func Gopt_Sprite_OnKey2(sprite interface{}, a string, fn func(key string)) {
func Gopt_Sprite_OnKey2(sprite any, a string, fn func(key string)) {
}
4 changes: 2 additions & 2 deletions cl/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,15 +977,15 @@ func compileType(ctx *blockCtx, t *ast.TypeSpec) {
}

type (
valueMap map[interface{}][]valueType // underlying Go value -> valueType
valueMap map[any][]valueType // underlying Go value -> valueType
valueType struct {
pos token.Pos
typ types.Type
}
)

// goVal returns the Go value for val, or nil.
func goVal(val constant.Value) interface{} {
func goVal(val constant.Value) any {
// val should exist, but be conservative and check
if val == nil {
return nil
Expand Down
6 changes: 3 additions & 3 deletions cmd/internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func runCmd(_ *base.Command, args []string) {
log.Fatalln("run go env failed:", err)
}

var gopEnv map[string]interface{}
var gopEnv map[string]any
if err := json.Unmarshal(stdout.Bytes(), &gopEnv); err != nil {
log.Fatal("decode json of go env failed:", err)
}
Expand All @@ -82,7 +82,7 @@ func runCmd(_ *base.Command, args []string) {
outputEnvVars(gopEnv, vars, *envJson)
}

func outputEnvVars(gopEnv map[string]interface{}, vars []string, outputJson bool) {
func outputEnvVars(gopEnv map[string]any, vars []string, outputJson bool) {
onlyValues := true

if len(vars) == 0 {
Expand All @@ -94,7 +94,7 @@ func outputEnvVars(gopEnv map[string]interface{}, vars []string, outputJson bool
}
sort.Strings(vars)
} else {
newEnv := make(map[string]interface{})
newEnv := make(map[string]any)
for _, v := range vars {
if value, ok := gopEnv[v]; ok {
newEnv[v] = value
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/help/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (w *errWriter) Write(b []byte) (int, error) {
}

// tmpl executes the given template text on data, writing the result to w.
func tmpl(w io.Writer, text string, data interface{}) {
func tmpl(w io.Writer, text string, data any) {
t := template.New("top")
t.Funcs(template.FuncMap{"trim": strings.TrimSpace, "capitalize": capitalize})
template.Must(t.Parse(text))
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/mod/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func check(err error) {
}
}

func fatal(msg interface{}) {
func fatal(msg any) {
fmt.Fprintln(os.Stderr, msg)
os.Exit(1)
}
2 changes: 1 addition & 1 deletion demo/mixgo/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import "fmt"

func p(a interface{}) {
func p(a any) {
sayMix()
fmt.Println("Hello,", a)
}
2 changes: 1 addition & 1 deletion format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const parserMode = parser.ParseComments
//
// The function may return early (before the entire result is written)
// and return a formatting error, for instance due to an incorrect AST.
func Node(dst io.Writer, fset *token.FileSet, node interface{}) error {
func Node(dst io.Writer, fset *token.FileSet, node any) error {
// Determine if we have a complete source file (file != nil).
var file *ast.File
var cnode *printer.CommentedNode
Expand Down
Loading