1
0
mirror of https://github.com/golang/go synced 2024-11-23 01:30:02 -07:00
go/test/fixedbugs/issue38905.go
Cuong Manh Le 0031fa80a3 cmd/compile: another fix initializing blank fields in struct literal
CL 230121 fixed the bug that struct literal blank fields type array/struct
can not be initialized. But it still misses some cases when an expression
causes "candiscard(value)" return false. When these happen, we recursively
call fixedlit with "var_" set to "_", and hit the bug again.

To fix it, just making splitnode return "nblank" whenever "var_" is "nblank".

Fixes #38905

Change-Id: I281941b388acbd551a4d8ca1a235477f8d26fb6e
Reviewed-on: https://go-review.googlesource.com/c/go/+/232617
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-08-15 03:09:21 +00:00

19 lines
509 B
Go

// compile
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Make sure that literal value can be passed to struct
// blank field with expressions where candiscard(value)
// returns false, see #38905.
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]}}} }