mirror of
https://github.com/golang/go
synced 2024-11-11 12:49:30 +00:00
2493072db6
There's no need for a and b to match types. The typechecker already ensured that a and b are both slices with the same base type, or a and b are (possibly named) []byte and string. The optimization to treat append(b, make([], ...)) as a zeroing slice extension doesn't fire when there's a OCONVNOP wrapping the make. Fixes #53888 Change-Id: Ied871ed0bbb8e4a4b35d280c71acbab8103691bc Reviewed-on: https://go-review.googlesource.com/c/go/+/418475 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Keith Randall <khr@golang.org>
38 lines
707 B
Go
38 lines
707 B
Go
// run
|
|
|
|
// Copyright 2018 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 (
|
|
"strings"
|
|
)
|
|
|
|
type T struct{}
|
|
|
|
const maxInt = int(^uint(0) >> 1)
|
|
|
|
func main() {
|
|
s := make([]T, maxInt)
|
|
shouldPanic("len out of range", func() { s = append(s, T{}) })
|
|
var oneElem = make([]T, 1)
|
|
shouldPanic("len out of range", func() { s = append(s, oneElem...) })
|
|
}
|
|
|
|
func shouldPanic(str string, f func()) {
|
|
defer func() {
|
|
err := recover()
|
|
if err == nil {
|
|
panic("did not panic")
|
|
}
|
|
s := err.(error).Error()
|
|
if !strings.Contains(s, str) {
|
|
panic("got panic " + s + ", want " + str)
|
|
}
|
|
}()
|
|
|
|
f()
|
|
}
|