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" errors initializing blank fields in struct literal #38905

Open
mdempsky opened this issue May 6, 2020 · 3 comments
Labels
Milestone

Comments

@mdempsky
Copy link
Member

@mdempsky mdempsky commented May 6, 2020

Following up on #38690, this code is valid and accepted by go/types, but cmd/compile fails to accept it:

package p

type t struct{ _ u }
type u [10]int

func f(x int) t   { return t{u{1 / x, 1 % x}} }
func g(p *int) t  { return t{u{*p}} }
func h(s []int) t { return t{u{s[0]}} }

These are expressions where candiscard(value) returns false.

Note that only one error message is printed, but that's because we hit a Fatalf after the error (use go tool compile -d panic to see it). You can also comment out some of the functions or shuffle their order to see that any of them alone triggers the failure.

Fails to compile in Go 1.14 too, so not a regression.

/cc @cuonglm

@mdempsky mdempsky added the NeedsFix label May 6, 2020
@mdempsky mdempsky added this to the Go1.16 milestone May 6, 2020
@mdempsky
Copy link
Member Author

@mdempsky mdempsky commented May 6, 2020

It looks like one possible fix is to have splitnode return nblank whenever var_ == nblank.

@mdempsky
Copy link
Member Author

@mdempsky mdempsky commented May 6, 2020

Slightly better test case that provides better coverage of splitnode:

package p

type t struct{ _ u }
type u [10]struct{ f int }

func f(x int) t   { return t{u{{1 / x}, {1 % x}}} }
func g(p *int) t  { return t{u{{*p}}} }
func h(s []int) t { return t{u{{s[0]}}} }
@gopherbot
Copy link

@gopherbot gopherbot commented May 6, 2020

Change https://golang.org/cl/232617 mentions this issue: cmd/compile: another fix initializing blank fields in struct literal

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.

None yet
2 participants
You can’t perform that action at this time.