diff --git a/exportloopref_test.go b/exportloopref_test.go index 444a80c..48a1724 100644 --- a/exportloopref_test.go +++ b/exportloopref_test.go @@ -46,3 +46,13 @@ func TestDepPointer(t *testing.T) { testdata := analysistest.TestData() analysistest.Run(t, testdata, exportloopref.Analyzer, "deeppointer") } + +func TestBreak(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, exportloopref.Analyzer, "break") +} + +func TestReturn(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, exportloopref.Analyzer, "return") +} diff --git a/testdata/src/break/break.go b/testdata/src/break/break.go new file mode 100644 index 0000000..f4dc0d1 --- /dev/null +++ b/testdata/src/break/break.go @@ -0,0 +1,10 @@ +package main + +func main() { + var result *int + haystack := []int{1, 2} + for _, hay := range haystack { + result = &hay // Broken just below, the loop does NOT set unexpected value to result + break + } +} diff --git a/testdata/src/return/return.go b/testdata/src/return/return.go new file mode 100644 index 0000000..acf9a90 --- /dev/null +++ b/testdata/src/return/return.go @@ -0,0 +1,15 @@ +package main + +func main() { + result := sub() + println(*result) +} + +func sub() (result *int) { + haystack := []int{1, 2} + for _, hay := range haystack { + result = &hay // Returns just below, the loop does NOT set unexpected value to result + return + } + return +}