diff options
author | Keith Randall <khr@golang.org> | 2021-09-09 08:09:57 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2021-09-09 15:34:08 +0000 |
commit | 19457a58e565ff5b480c3806fe02fbc7ccdf32f0 (patch) | |
tree | 4698c72635ef6c62e1696810aef4ab506af3909d /test | |
parent | a295b3cec80b048048bf51a0462764dc337ca6ef (diff) | |
download | go-19457a58e565ff5b480c3806fe02fbc7ccdf32f0.tar.gz go-19457a58e565ff5b480c3806fe02fbc7ccdf32f0.zip |
cmd/compile: stenciled conversions might be NOPs
A generic conversion might be required for when converting T->interface{}.
When stenciled with T=interface{}, then that conversion doesn't need
to do anything.
Fixes #48276
Change-Id: Ife65d01c99fbd0895cb7eec79df9e93e752b1fa5
Reviewed-on: https://go-review.googlesource.com/c/go/+/348736
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/typeparam/issue48276a.go | 19 | ||||
-rw-r--r-- | test/typeparam/issue48276a.out | 1 | ||||
-rw-r--r-- | test/typeparam/issue48276b.go | 15 |
3 files changed, 35 insertions, 0 deletions
diff --git a/test/typeparam/issue48276a.go b/test/typeparam/issue48276a.go new file mode 100644 index 0000000000..060ac3eb7f --- /dev/null +++ b/test/typeparam/issue48276a.go @@ -0,0 +1,19 @@ +// run -gcflags=-G=3 + +// Copyright 2021 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" + +func main() { + IsZero[interface{}]("") +} + +func IsZero[T comparable](val T) bool { + var zero T + fmt.Printf("%v:%v\n", zero, val) + return val != zero +} diff --git a/test/typeparam/issue48276a.out b/test/typeparam/issue48276a.out new file mode 100644 index 0000000000..7e8a8a9a2e --- /dev/null +++ b/test/typeparam/issue48276a.out @@ -0,0 +1 @@ +<nil>: diff --git a/test/typeparam/issue48276b.go b/test/typeparam/issue48276b.go new file mode 100644 index 0000000000..67c3e3d9f5 --- /dev/null +++ b/test/typeparam/issue48276b.go @@ -0,0 +1,15 @@ +// run -gcflags=-G=3 + +// Copyright 2021 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 + +func main() { + f[interface{}](nil) +} + +func f[T any](x T) { + var _ interface{} = x +} |