diff options
| author | Keith Randall <khr@golang.org> | 2022-06-02 09:31:30 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-03-08 16:23:09 +0000 |
| commit | 54d05e4e252298724c5615ea2a4e36f2151b22ce (patch) | |
| tree | 59fcab230747265eb3190f4e5aaecf5e56025bfb /test/typeparam | |
| parent | 8b3961264120d188c3c9739370826e346d8748c2 (diff) | |
| download | go-54d05e4e252298724c5615ea2a4e36f2151b22ce.tar.xz | |
test: test for issue 53087
This issue has been fixed with unified IR, so just add a test.
Update #53087
Change-Id: I965d9f27529fa6b7c89e2921c65e5a100daeb9fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/410197
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Keith Randall <khr@google.com>
Diffstat (limited to 'test/typeparam')
| -rw-r--r-- | test/typeparam/issue53087.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/typeparam/issue53087.go b/test/typeparam/issue53087.go new file mode 100644 index 0000000000..5e19c59f1f --- /dev/null +++ b/test/typeparam/issue53087.go @@ -0,0 +1,56 @@ +// run + +// Copyright 2022 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 I interface { + M() +} + +type S struct { + str string +} + +func (s *S) M() {} + +var _ I = &S{} + +type CloningMap[K comparable, V any] struct { + inner map[K]V +} + +func (cm CloningMap[K, V]) With(key K, value V) CloningMap[K, V] { + result := CloneBad(cm.inner) + result[key] = value + return CloningMap[K, V]{result} +} + +func CloneBad[M ~map[K]V, K comparable, V any](m M) M { + r := make(M, len(m)) + for k, v := range m { + r[k] = v + } + return r +} + +func main() { + s1 := &S{"one"} + s2 := &S{"two"} + + m := CloningMap[string, I]{inner: make(map[string]I)} + m = m.With("a", s1) + m = m.With("b", s2) + + it, found := m.inner["a"] + if !found { + panic("a not found") + } + if _, ok := it.(*S); !ok { + panic(fmt.Sprintf("got %T want *main.S", it)) + } +} |
