Giter VIP home page Giter VIP logo

Comments (3)

gordonklaus avatar gordonklaus commented on August 23, 2024

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.

dolmen avatar dolmen commented on August 23, 2024

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.

dolmen avatar dolmen commented on August 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.