Skip to content

Commit

Permalink
pattern: don't panic on index expressions of parenthesized expressions
Browse files Browse the repository at this point in the history
Closes: gh-1400
  • Loading branch information
dominikh committed Apr 28, 2023
1 parent bb0858e commit bc668a1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pattern/match.go
Expand Up @@ -6,6 +6,8 @@ import (
"go/token"
"go/types"
"reflect"

"golang.org/x/tools/go/ast/astutil"
)

var tokensByString = map[string]Token{
Expand Down Expand Up @@ -560,13 +562,14 @@ func (fn Symbol) Match(m *Matcher, node interface{}) (interface{}, bool) {
return nil, false
}

fun := r
fun := r.(ast.Expr)
switch idx := fun.(type) {
case *ast.IndexExpr:
fun = idx.X
case *ast.IndexListExpr:
fun = idx.X
}
fun = astutil.Unparen(fun)

switch fun := fun.(type) {
case *ast.Ident:
Expand Down

0 comments on commit bc668a1

Please sign in to comment.