Skip to content

Commit d64ed6a

Browse files
committed
internal/refactor/inline: audit for types.Alias safety
Updates golang/go#65294 Change-Id: I14f7d06a0e41799238707b20a88205ae1bfc1ce8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/562036 Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]> Commit-Queue: Alan Donovan <[email protected]>
1 parent 0d87589 commit d64ed6a

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

internal/refactor/inline/escape.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func escape(info *types.Info, root ast.Node, f func(v *types.Var, escapes bool))
7272
if sel, ok := n.Fun.(*ast.SelectorExpr); ok {
7373
if seln, ok := info.Selections[sel]; ok &&
7474
seln.Kind() == types.MethodVal &&
75-
isPointer(seln.Obj().Type().(*types.Signature).Recv().Type()) {
75+
isPointer(seln.Obj().Type().Underlying().(*types.Signature).Recv().Type()) {
7676
tArg, indirect := effectiveReceiver(seln)
7777
if !indirect && !isPointer(tArg) {
7878
lvalue(sel.X, true) // &x.f

internal/refactor/inline/falcon.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"strings"
1818

1919
"golang.org/x/tools/go/types/typeutil"
20+
"golang.org/x/tools/internal/aliases"
2021
"golang.org/x/tools/internal/typeparams"
2122
)
2223

@@ -446,7 +447,7 @@ func (st *falconState) expr(e ast.Expr) (res any) { // = types.TypeAndValue | as
446447
// - for an array or *array, use [n]int.
447448
// The last two entail progressively stronger index checks.
448449
var ct ast.Expr // type syntax for constraint
449-
switch t := t.(type) {
450+
switch t := aliases.Unalias(t).(type) {
450451
case *types.Map:
451452
if types.IsInterface(t.Key()) {
452453
ct = &ast.MapType{

internal/refactor/inline/inline.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ func arguments(caller *Caller, calleeDecl *ast.FuncDecl, assign1 func(*types.Var
11541154

11551155
// Make * or & explicit.
11561156
argIsPtr := isPointer(arg.typ)
1157-
paramIsPtr := isPointer(seln.Obj().Type().(*types.Signature).Recv().Type())
1157+
paramIsPtr := isPointer(seln.Obj().Type().Underlying().(*types.Signature).Recv().Type())
11581158
if !argIsPtr && paramIsPtr {
11591159
// &recv
11601160
arg.expr = &ast.UnaryExpr{Op: token.AND, X: arg.expr}

internal/refactor/inline/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func indirectSelection(seln *types.Selection) bool {
132132
return true
133133
}
134134

135-
tParam := seln.Obj().Type().(*types.Signature).Recv().Type()
135+
tParam := seln.Obj().Type().Underlying().(*types.Signature).Recv().Type()
136136
return isPointer(tArg) && !isPointer(tParam) // implicit *
137137
}
138138

0 commit comments

Comments
 (0)