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

cmd/compile: cannot use _ as value #17963

Closed
go101 opened this issue Nov 17, 2016 · 2 comments
Closed

cmd/compile: cannot use _ as value #17963

go101 opened this issue Nov 17, 2016 · 2 comments
Milestone

Comments

@go101
Copy link

go101 commented Nov 17, 2016

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.7.3 linux/amd64

What did you do?

package main

func main() {
	var _ = struct{}{} // ok
	
	_ = struct{
		a int
	}{
		a: 1, // ok
	}
	
	var _ = struct{
		a int
	}{
		a: 1, // cannot use _ as value
	}
}

What did you expect to see?

compile ok

What did you see instead?

compile error

@bradfitz bradfitz changed the title compiler bug? cmd/compile: cannot use _ as value Nov 17, 2016
@go101
Copy link
Author

go101 commented Nov 17, 2016

I just googled this problem and found a similar issue: #15481

A summary:

package main

func main() {
    var _ = struct{a int}{}
    var _ = [5]int{}
    var _ = map[string]int{}

    _ = struct{a int}{1}
    _ = [5]int{1}
    _ = map[string]int{"a": 1}
    _ = struct {a int}{a: 1}

    var _ = struct {}{}
    var _ = []int{1}

    // aboves are all ok
    // belows are all errors

    var _ = struct{a int}{1}
    var _ = map[string]int{"a": 1}
    var _ = [5]int{1}
    var _ = struct {a int}{a: 1}
}

@ianlancetaylor ianlancetaylor added this to the Go1.9 milestone Nov 17, 2016
@griesemer
Copy link
Contributor

Duplicate of #15481.

@golang golang locked and limited conversation to collaborators Nov 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants