diff --git a/gcassert.go b/gcassert.go index cf3f81e..11266b6 100644 --- a/gcassert.go +++ b/gcassert.go @@ -390,10 +390,11 @@ func (v *inlinedDeclVisitor) Visit(node ast.Node) (w ast.Visitor) { obj = v.p.TypesInfo.Uses[n] case *ast.SelectorExpr: sel := v.p.TypesInfo.Selections[n] - if sel == nil { - break + if sel != nil { + obj = sel.Obj() + } else { + obj = v.p.TypesInfo.Uses[n.Sel] } - obj = sel.Obj() } if _, ok := v.mustInlineFuncs[obj]; ok { lineInfo := v.directiveMap[lineNumber] diff --git a/gcassert_test.go b/gcassert_test.go index 7364430..f0567a6 100644 --- a/gcassert_test.go +++ b/gcassert_test.go @@ -99,13 +99,14 @@ testdata/inline.go:51: sum += notInlinable(i): call was not inlined testdata/inline.go:55: sum += 1: call was not inlined testdata/inline.go:58: test(0).neverInlinedMethod(10): call was not inlined testdata/inline.go:60: otherpkg.A{}.NeverInlined(sum): call was not inlined +testdata/inline.go:62: otherpkg.NeverInlinedFunc(sum): call was not inlined testdata/issue5.go:4: Gen().Layout(): call was not inlined ` testCases := []struct{ - name string - pkgs []string - cwd string + name string + pkgs []string + cwd string expected string }{ { @@ -130,7 +131,7 @@ testdata/issue5.go:4: Gen().Layout(): call was not inlined "./testdata", "./testdata/otherpkg", }, - cwd: cwd, + cwd: cwd, expected: expectedOutput, }, } diff --git a/testdata/inline.go b/testdata/inline.go index 4b4be57..46601a1 100644 --- a/testdata/inline.go +++ b/testdata/inline.go @@ -58,4 +58,6 @@ func caller() { sum += test(0).neverInlinedMethod(10) otherpkg.A{}.NeverInlined(sum) + + otherpkg.NeverInlinedFunc(sum) } diff --git a/testdata/otherpkg/foo.go b/testdata/otherpkg/foo.go index 2dfdfc7..71e21c5 100644 --- a/testdata/otherpkg/foo.go +++ b/testdata/otherpkg/foo.go @@ -10,3 +10,10 @@ func (a A) NeverInlined(n int) { fmt.Println(i) } } + +//gcassert:inline +func NeverInlinedFunc(n int) { + for i := 0; i < n; i++ { + fmt.Println(i) + } +}