Coder Social home page Coder Social logo

SSA and generics (go1.18) about wastedassign HOT 7 CLOSED

ldez avatar ldez commented on June 12, 2024 5
SSA and generics (go1.18)

from wastedassign.

Comments (7)

migregal avatar migregal commented on June 12, 2024 1

Hi, everyone!

Is there any movement about go1.19 release? Actually, i can't reproduce that problem with new version:

main.go

package main

import "fmt"

func wastedassignG[T ~int](hoge T) {
	var i int
	for {
		i = 5
	}

	fmt.Println(i)
}

func wastedassign(hoge int) {
	var i int
	for {
		i = 5
	}

	fmt.Println(i)
}

func main() {

}

And it gives me this output:

$ go vet -vettool=`which wastedassign` ./main/...                                                                                          
# <path>/main
main/main.go:8:3: assigned to i, but reassigned without using the value
main/main.go:17:3: assigned to i, but reassigned without using the value

Seems like it was fixed and golangci-lint can reenable wastedassign?

from wastedassign.

sanposhiho avatar sanposhiho commented on June 12, 2024

Hm, thanks for informing. wait for a new version of SSA.

from wastedassign.

ldez avatar ldez commented on June 12, 2024

SSA has been updated and it seems to work inside golangci-lint.

from wastedassign.

sanposhiho avatar sanposhiho commented on June 12, 2024

Thanks

from wastedassign.

ldez avatar ldez commented on June 12, 2024

in fact, the problem is still here

from wastedassign.

ldez avatar ldez commented on June 12, 2024

The code of the linter needs to be adapted to manage generics:

func wastedassignG[T ~int](hoge T) {
	var i int
	for {
		hoge = 5 // <- not detected KO
		// break
	}

	println(i)
	println(hoge)
	return
}

func wastedassign(hoge int) {
	var i int
	for {
		hoge = 5 // <- detected OK
		// break
	}

	println(i)
	println(hoge)
	return
}

from wastedassign.

ldez avatar ldez commented on June 12, 2024

go1.19 will come in about 2 weeks, it can be good if you can fix your linter before this release.

from wastedassign.

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.