Skip to content

Commit

Permalink
reproduce #13
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoh86 committed Nov 16, 2022
1 parent bc0c835 commit 4ad8bcf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions exportloopref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ func TestDepPointer(t *testing.T) {
testdata := analysistest.TestData()
analysistest.Run(t, testdata, exportloopref.Analyzer, "deeppointer")
}

func TestReRef(t *testing.T) {
testdata := analysistest.TestData()
analysistest.Run(t, testdata, exportloopref.Analyzer, "reref")
}
4 changes: 4 additions & 0 deletions testdata/src/reref/another_file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package main

// Moving this map to main.go fixes nil pointer deference
var globalMapInDifferentFile = map[int]*MyStruct{}
13 changes: 13 additions & 0 deletions testdata/src/reref/issue13.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

type MyStruct struct {
MyStructPtrField *int
}

func main() {
localVal := 0
arr := []MyStruct{{&localVal}}
for _, p := range arr {
t := *p.MyStructPtrField
globalMapInDifferentFile[t] = &p // want "exporting a pointer for the loop variable p"
}

0 comments on commit 4ad8bcf

Please sign in to comment.