mirror of
https://github.com/golang/go
synced 2024-11-25 12:27:57 -07:00
eb6c433eb3
Don't convert values that aren't Go constants, like uintptr(unsafe.Pointer(nil)), to a literal constant. This avoids assuming they are constants for things like indexing, array sizes, case duplication, etc. Also, nil is an allowed duplicate in switches. CTNILs aren't Go constants. Fixes #28078 Fixes #28079 Change-Id: I9ab8af47098651ea09ef10481787eae2ae2fb445 Reviewed-on: https://go-review.googlesource.com/c/151320 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
35 lines
572 B
Go
35 lines
572 B
Go
// compile
|
|
|
|
// 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.
|
|
|
|
// Non-constant duplicate keys/cases should not be reported
|
|
// as errors by the compiler.
|
|
|
|
package p
|
|
|
|
import "unsafe"
|
|
|
|
func f() {
|
|
_ = map[uintptr]int{
|
|
0: 0,
|
|
uintptr(unsafe.Pointer(nil)): 0,
|
|
}
|
|
|
|
switch uintptr(0) {
|
|
case 0:
|
|
case uintptr(unsafe.Pointer(nil)):
|
|
}
|
|
|
|
switch interface{}(nil) {
|
|
case nil:
|
|
case nil:
|
|
}
|
|
|
|
_ = map[interface{}]int{
|
|
nil: 0,
|
|
nil: 0,
|
|
}
|
|
}
|