Skip to content

Commit 02ac14b

Browse files
committed
Use types.Func.Origin instead of typeparams.OriginMethod
The Origin method was added in Go 1.19. Using it also avoids a bug in typeparams.OriginMethod, where methods named "_" lead to panics. (cherry picked from commit 65cc494)
1 parent d31a6b5 commit 02ac14b

File tree

4 files changed

+4
-10
lines changed

4 files changed

+4
-10
lines changed

go/ir/methods.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"go/types"
1212

1313
"honnef.co/go/tools/analysis/lint"
14-
15-
"golang.org/x/exp/typeparams"
1614
)
1715

1816
// MethodValue returns the Function implementing method sel, building
@@ -118,7 +116,7 @@ func (prog *Program) RuntimeTypes() []types.Type {
118116
// declaredFunc returns the concrete function/method denoted by obj.
119117
// Panic ensues if there is none.
120118
func (prog *Program) declaredFunc(obj *types.Func) *Function {
121-
if origin := typeparams.OriginMethod(obj); origin != obj {
119+
if origin := obj.Origin(); origin != obj {
122120
// Calling method on instantiated type, create a wrapper that calls the generic type's method
123121
base := prog.packageLevelValue(origin)
124122
return makeInstance(prog, base.(*Function), obj.Type().(*types.Signature), nil)

go/ir/source.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"go/ast"
1515
"go/token"
1616
"go/types"
17-
18-
"golang.org/x/exp/typeparams"
1917
)
2018

2119
// EnclosingFunction returns the function that contains the syntax
@@ -170,7 +168,7 @@ func (prog *Program) packageLevelValue(obj types.Object) Value {
170168
// TODO(adonovan): check the invariant that obj.Type() matches the
171169
// result's Signature, both in the params/results and in the receiver.
172170
func (prog *Program) FuncValue(obj *types.Func) *Function {
173-
obj = typeparams.OriginMethod(obj)
171+
obj = obj.Origin()
174172
fn, _ := prog.packageLevelValue(obj).(*Function)
175173
return fn
176174
}

staticcheck/lint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3182,7 +3182,7 @@ func CheckDeprecated(pass *analysis.Pass) (interface{}, error) {
31823182

31833183
obj := pass.TypesInfo.ObjectOf(sel.Sel)
31843184
if obj_, ok := obj.(*types.Func); ok {
3185-
obj = typeparams.OriginMethod(obj_)
3185+
obj = obj_.Origin()
31863186
}
31873187
if obj.Pkg() == nil {
31883188
return true

unused/unused.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"honnef.co/go/tools/go/ast/astutil"
1818
"honnef.co/go/tools/go/types/typeutil"
1919

20-
"golang.org/x/exp/typeparams"
2120
"golang.org/x/tools/go/analysis"
2221
"golang.org/x/tools/go/types/objectpath"
2322
)
@@ -1151,8 +1150,7 @@ func (g *graph) decl(decl ast.Decl, by types.Object) {
11511150
}
11521151

11531152
case *ast.FuncDecl:
1154-
// XXX calling OriginMethod is unnecessary if we use types.Func.Origin
1155-
obj := typeparams.OriginMethod(g.info.ObjectOf(decl.Name).(*types.Func))
1153+
obj := g.info.ObjectOf(decl.Name).(*types.Func).Origin()
11561154
g.see(obj, nil)
11571155

11581156
if token.IsExported(decl.Name.Name) && g.opts.ExportedIsUsed {

0 commit comments

Comments
 (0)