mirror of
https://github.com/golang/go
synced 2024-11-17 07:45:09 -07:00
a9e107c85c
If a slice's entries are sparse, we decide to initialize it dynamically instead of statically. That's CL 151319. But if we do initialize it dynamically, we still need to initialize the static entries. Typically we do that, but the bug fixed here is that we don't if the entry's value is itself an array or struct. To fix, use initKindLocalCode to ensure that both static and dynamic entries are initialized via code. Fixes #31987 Change-Id: I1192ffdbfb5cd50445c1206c4a3d8253295201dd Reviewed-on: https://go-review.googlesource.com/c/go/+/176904 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
23 lines
414 B
Go
23 lines
414 B
Go
// run
|
|
|
|
// Copyright 2019 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.
|
|
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
type container struct {
|
|
Value string
|
|
}
|
|
|
|
func main() {
|
|
s := []container{
|
|
7: {Value: "string value"},
|
|
}
|
|
if s[7].Value != "string value" {
|
|
panic(fmt.Errorf("wanted \"string value\", got \"%s\"", s[7].Value))
|
|
}
|
|
}
|