Comments (3)
Nice find, thanks for the report.
(Note to self: To fix ineffassign, I would conservatively mark any variable that is the target of a slice operation as "escaping" (meaning it should never be reported as an ineffectual assignment). This could end up silencing some true positives, but I suspect not many.)
from ineffassign.
I think that the case to consider here is that any array variable from which a slice is built will escape analysis from that point. Because the array data may be modified directly via the array but also through the slice (or through any other slice derived from that slice, or any function that takes the slice as a parameter).
from ineffassign.
This is in fact the same case of escape as with pointers:
package main
func main() {
var i int
p := &i
f(p)
i = 0
f(p)
var arr [1]int
s := arr[:]
g(s)
arr = [1]int{}
g(s)
}
func f(*int) {}
func g([]int) {}
f
can modify i
through p
, so as soon as a pointer to i
is taken, i
can't be statically tracked.
g
can modify arr
through s
, so as soon as a slice to arr
is taken, arr
can't be statically tracked.
from ineffassign.
Related Issues (20)
- Unexpected ineffectual assignment: type switch HOT 1
- Initialization as nil treated as assignment HOT 2
- What is causing this ineffassign? HOT 2
- False positive or explain: could not import C (no metadata for C) HOT 3
- Not able to detect inherited properties. HOT 5
- Why is this not reported ? HOT 5
- "Ineffectual assignment" false positive when var used in deferred function call HOT 2
- Why the two cases have different results? HOT 2
- false positive in `switch { case... case... }` HOT 1
- Check for reassignment error HOT 6
- [PANIC] Running against large code-base after update HOT 1
- false positive for map variable HOT 1
- false positivie: previously declared variable HOT 1
- false positive: warning: ineffectual assignment to tm HOT 2
- Bump golang.org/x/tools to v0.7.0 (as minimum) and make new tag HOT 3
- control variable used on defer HOT 1
- fails to flag ineffectual reassignment after usage of waitgroups/errorgroups HOT 1
- Ineff. assignment to local variable not detected in presence of defer or *sync.Mutex HOT 4
- Publish tags and releases HOT 4
- ineffassign flagged on `err` assignment in for-loop. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ineffassign.