From d64ed6ae4ce26ac4a29f26dda999e24bf027f9b8 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Tue, 6 Feb 2024 15:57:13 -0500 Subject: [PATCH] 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Robert Findley Commit-Queue: Alan Donovan --- internal/refactor/inline/escape.go | 2 +- internal/refactor/inline/falcon.go | 3 ++- internal/refactor/inline/inline.go | 2 +- internal/refactor/inline/util.go | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/refactor/inline/escape.go b/internal/refactor/inline/escape.go index 795ad4feab6..a3f5e555e9f 100644 --- a/internal/refactor/inline/escape.go +++ b/internal/refactor/inline/escape.go @@ -72,7 +72,7 @@ func escape(info *types.Info, root ast.Node, f func(v *types.Var, escapes bool)) if sel, ok := n.Fun.(*ast.SelectorExpr); ok { if seln, ok := info.Selections[sel]; ok && seln.Kind() == types.MethodVal && - isPointer(seln.Obj().Type().(*types.Signature).Recv().Type()) { + isPointer(seln.Obj().Type().Underlying().(*types.Signature).Recv().Type()) { tArg, indirect := effectiveReceiver(seln) if !indirect && !isPointer(tArg) { lvalue(sel.X, true) // &x.f diff --git a/internal/refactor/inline/falcon.go b/internal/refactor/inline/falcon.go index 9863e8dbcfb..1b2cb746ade 100644 --- a/internal/refactor/inline/falcon.go +++ b/internal/refactor/inline/falcon.go @@ -17,6 +17,7 @@ import ( "strings" "golang.org/x/tools/go/types/typeutil" + "golang.org/x/tools/internal/aliases" "golang.org/x/tools/internal/typeparams" ) @@ -446,7 +447,7 @@ func (st *falconState) expr(e ast.Expr) (res any) { // = types.TypeAndValue | as // - for an array or *array, use [n]int. // The last two entail progressively stronger index checks. var ct ast.Expr // type syntax for constraint - switch t := t.(type) { + switch t := aliases.Unalias(t).(type) { case *types.Map: if types.IsInterface(t.Key()) { ct = &ast.MapType{ diff --git a/internal/refactor/inline/inline.go b/internal/refactor/inline/inline.go index 7eaa6bff3f5..24ffb55fd1a 100644 --- a/internal/refactor/inline/inline.go +++ b/internal/refactor/inline/inline.go @@ -1154,7 +1154,7 @@ func arguments(caller *Caller, calleeDecl *ast.FuncDecl, assign1 func(*types.Var // Make * or & explicit. argIsPtr := isPointer(arg.typ) - paramIsPtr := isPointer(seln.Obj().Type().(*types.Signature).Recv().Type()) + paramIsPtr := isPointer(seln.Obj().Type().Underlying().(*types.Signature).Recv().Type()) if !argIsPtr && paramIsPtr { // &recv arg.expr = &ast.UnaryExpr{Op: token.AND, X: arg.expr} diff --git a/internal/refactor/inline/util.go b/internal/refactor/inline/util.go index 267ef745e32..7581ca29a50 100644 --- a/internal/refactor/inline/util.go +++ b/internal/refactor/inline/util.go @@ -132,7 +132,7 @@ func indirectSelection(seln *types.Selection) bool { return true } - tParam := seln.Obj().Type().(*types.Signature).Recv().Type() + tParam := seln.Obj().Type().Underlying().(*types.Signature).Recv().Type() return isPointer(tArg) && !isPointer(tParam) // implicit * }