Skip to content

Commit

Permalink
test: test for issue 53087
Browse files Browse the repository at this point in the history
This issue has been fixed with unified IR, so just add a test.

Update golang#53087

Change-Id: I965d9f27529fa6b7c89e2921c65e5a100daeb9fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/410197
Reviewed-by: Cuong Manh Le <[email protected]>
Reviewed-by: Emmanuel Odeke <[email protected]>
Run-TryBot: Keith Randall <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
Reviewed-by: Carlos Amedee <[email protected]>
Auto-Submit: Keith Randall <[email protected]>
  • Loading branch information
randall77 authored and gopherbot committed Mar 8, 2023
1 parent 8b39612 commit 54d05e4
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/typeparam/issue53087.go
Original file line number Diff line number Diff line change
@@ -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))
}
}

0 comments on commit 54d05e4

Please sign in to comment.