Skip to content

Commit

Permalink
internal/refactor/inline: audit for types.Alias safety
Browse files Browse the repository at this point in the history
Updates golang/go#65294

Change-Id: I14f7d06a0e41799238707b20a88205ae1bfc1ce8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/562036
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
  • Loading branch information
adonovan committed Feb 6, 2024
1 parent 0d87589 commit d64ed6a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/refactor/inline/escape.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion internal/refactor/inline/falcon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion internal/refactor/inline/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion internal/refactor/inline/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
}

Expand Down

0 comments on commit d64ed6a

Please sign in to comment.