Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redundant assignment statement for _,file := range files { file := file ...} #42141

Closed
XiaodongLoong opened this issue Oct 22, 2020 · 4 comments
Closed

Comments

@XiaodongLoong
Copy link

@XiaodongLoong XiaodongLoong commented Oct 22, 2020

There is a redundant assignment statement, I think it is no meaning:

file := file

XiaodongLoong added a commit to XiaodongLoong/go that referenced this issue Oct 22, 2020
…le ...}

golang#42141 (comment)

Signed-off-by: liuxiaodong <liuxiaodong@loongson.cn>
@pierrec
Copy link

@pierrec pierrec commented Oct 22, 2020

It is not redundant, it makes a copy of the file for the parallel test below.
See concurrency.

@martisch martisch closed this Oct 22, 2020
XiaodongLoong added a commit to XiaodongLoong/go that referenced this issue Oct 22, 2020
@martisch
Copy link
Contributor

@martisch martisch commented Oct 22, 2020

Note there is a long standing issue to detect the type of error that can happen if this copy was not made. #16520

I assume also the race detector may complain if the copy was not there.

@XiaodongLoong
Copy link
Author

@XiaodongLoong XiaodongLoong commented Oct 22, 2020

Thanks, I have gained knowledge!

@XiaodongLoong
Copy link
Author

@XiaodongLoong XiaodongLoong commented Oct 22, 2020

I write some code to test this issue:

package main

import "fmt"

func main() {
        a := []int{1,2,3}
        for x := range a {
                fmt.Println(x)
                fmt.Println(&x)
                x := x
                fmt.Println(&x)
        }
}

test logs:

$ go run main.go 
0
0xc00007e010
0xc00007e030
1
0xc00007e010
0xc00007e040
2
0xc00007e010
0xc00007e050
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.