Skip to content

Commit

Permalink
add inline tests for anonymous function callsites
Browse files Browse the repository at this point in the history
The `//gcassert:inline` directive already works for callsites of
anonymous functions. This commit adds tests for this case.
  • Loading branch information
mgartner committed Jan 3, 2025
1 parent 778fb58 commit c0b40bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gcassert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func badDirective3() {
55: {directives: []assertDirective{inline}},
57: {inlinableCallsites: []passInfo{{colNo: 36}}},
58: {inlinableCallsites: []passInfo{{colNo: 35}}},
75: {directives: []assertDirective{inline}},
77: {directives: []assertDirective{inline}},
},
"testdata/noescape.go": {
11: {directives: []assertDirective{noescape}},
Expand Down Expand Up @@ -120,10 +122,11 @@ 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/inline.go:77: sum += anonNeverInlinedNoAssert(i): call was not inlined
testdata/issue5.go:4: Gen().Layout(): call was not inlined
`

testCases := []struct{
testCases := []struct {
name string
pkgs []string
cwd string
Expand Down
16 changes: 16 additions & 0 deletions testdata/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,20 @@ func caller() {
otherpkg.A{}.NeverInlined(sum)

otherpkg.NeverInlinedFunc(sum)

anonInlinedNoAssert := func(a int) int {
return a + 10
}

anonNeverInlinedNoAssert := func(a int) int {
fmt.Println(a)
return a + 10
}

for i := 0; i < 10; i++ {
//gcassert:inline
sum += anonInlinedNoAssert(i)
//gcassert:inline
sum += anonNeverInlinedNoAssert(i)
}
}

0 comments on commit c0b40bf

Please sign in to comment.