github-vet / github-vet/rangeloop-pointer-findings

kyoh86/exportloopref: testdata/src/simple/simple.go; 18 LoC

Open
#16,640 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [kyoh86/exportloopref](https://www.github.com/kyoh86/exportloopref) at [testdata/src/simple/simple.go](https://github.com/kyoh86/exportloopref/blob/d5f3d8ca651dde5fe8302a0f5abfef481e470944/testdata/src/simple/simple.go#L10-L27)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.

> reference to p is reassigned at line 13

[Click here to see the code in its original context.](https://github.com/kyoh86/exportloopref/blob/d5f3d8ca651dde5fe8302a0f5abfef481e470944/testdata/src/simple/simple.go#L10-L27)

Click here to show the 18 line(s) of Go which triggered the analyzer.

```go
for i, p := range []int{10, 11, 12, 13} {
printp(&p) // not a diagnostic
slice = append(slice, &p) // want "exporting a pointer for the loop variable p"
array[i] = &p // want "exporting a pointer for the loop variable p"
if i%2 == 0 {
ref = &p // want "exporting a pointer for the loop variable p"
str.x = &p // want "exporting a pointer for the loop variable p"
}
var vStr struct{ x *int }
var vArray [4]*int
var v *int
if i%2 == 0 {
v = &p // not a diagnostic (x is local variable)
vArray[1] = &p // not a diagnostic (x is local variable)
vStr.x = &p
}
_ = v
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: d5f3d8ca651dde5fe8302a0f5abfef481e470944

Contributor guide

No contributing guide indexed for this repository

Research direction

Read testdata/src/simple/simple.go at the referenced commit and review the analyzer message about the loop variable p. Compare the reported references with the comments marking expected diagnostics and local-variable cases. Done means leaving the issue's requested reaction class: Bug, Mitigated, or Desirable Behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
devtools
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.