From 2be5b846650aa4674a4eca7c11f303673b69a35a Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Mon, 18 Oct 2021 10:59:29 -0700 Subject: cmd/compile: allow importing and exporting of ODYNAMICTYPE Change-Id: I2fca7a801c85ed93c002c23bfcb0cf9593f1bdf4 Reviewed-on: https://go-review.googlesource.com/c/go/+/356571 Trust: Keith Randall Trust: Dan Scales Run-TryBot: Keith Randall TryBot-Result: Go Bot Reviewed-by: Dan Scales --- test/typeparam/issue49027.dir/a.go | 34 ++++++++++++++++++++++++++++++++++ test/typeparam/issue49027.dir/main.go | 8 ++++++++ 2 files changed, 42 insertions(+) (limited to 'test/typeparam') diff --git a/test/typeparam/issue49027.dir/a.go b/test/typeparam/issue49027.dir/a.go index d3ec27deab..da88297965 100644 --- a/test/typeparam/issue49027.dir/a.go +++ b/test/typeparam/issue49027.dir/a.go @@ -15,7 +15,41 @@ func conv[T any](v interface{}) T { func Conv2(v interface{}) (string, bool) { return conv2[string](v) } + func conv2[T any](v interface{}) (T, bool) { x, ok := v.(T) return x, ok } + +func Conv3(v interface{}) string { + return conv3[string](v) +} + +func conv3[T any](v interface{}) T { + switch v := v.(type) { + case T: + return v + default: + var z T + return z + } +} + +type Mystring string + +func (Mystring) Foo() { +} + +func Conv4(v interface{Foo()}) Mystring { + return conv4[Mystring](v) +} + +func conv4[T interface{Foo()}](v interface{Foo()}) T { + switch v := v.(type) { + case T: + return v + default: + var z T + return z + } +} diff --git a/test/typeparam/issue49027.dir/main.go b/test/typeparam/issue49027.dir/main.go index d0dc33d734..aa20a2fdfb 100644 --- a/test/typeparam/issue49027.dir/main.go +++ b/test/typeparam/issue49027.dir/main.go @@ -22,4 +22,12 @@ func main() { if y != s { panic(fmt.Sprintf("got %s wanted %s", y, s)) } + z := a.Conv3(s) + if z != s { + panic(fmt.Sprintf("got %s wanted %s", z, s)) + } + w := a.Conv4(a.Mystring(s)) + if w != a.Mystring(s) { + panic(fmt.Sprintf("got %s wanted %s", w, s)) + } } -- cgit v1.3-5-g9baa