Skip to content

Commit 4ad8bcf

Browse files
committed
reproduce #13
1 parent bc0c835 commit 4ad8bcf

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

exportloopref_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ func TestDepPointer(t *testing.T) {
4646
testdata := analysistest.TestData()
4747
analysistest.Run(t, testdata, exportloopref.Analyzer, "deeppointer")
4848
}
49+
50+
func TestReRef(t *testing.T) {
51+
testdata := analysistest.TestData()
52+
analysistest.Run(t, testdata, exportloopref.Analyzer, "reref")
53+
}

testdata/src/reref/another_file.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package main
2+
3+
// Moving this map to main.go fixes nil pointer deference
4+
var globalMapInDifferentFile = map[int]*MyStruct{}

testdata/src/reref/issue13.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
type MyStruct struct {
4+
MyStructPtrField *int
5+
}
6+
7+
func main() {
8+
localVal := 0
9+
arr := []MyStruct{{&localVal}}
10+
for _, p := range arr {
11+
t := *p.MyStructPtrField
12+
globalMapInDifferentFile[t] = &p // want "exporting a pointer for the loop variable p"
13+
}

0 commit comments

Comments
 (0)