diff options
author | Keith Randall <khr@golang.org> | 2021-08-09 11:40:46 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2021-08-10 01:56:50 +0000 |
commit | 2fbf6aafe7de215a1d03e14aa488aa8fd31f56a7 (patch) | |
tree | 41d56baf35963eed63ccefc51cb85e71c318a8f5 /test/typeparam/typeswitch6.go | |
parent | e4cfa2f6dad8c73e98a4149948ded424df9c8501 (diff) | |
download | go-2fbf6aafe7de215a1d03e14aa488aa8fd31f56a7.tar.gz go-2fbf6aafe7de215a1d03e14aa488aa8fd31f56a7.zip |
[dev.typeparams] cmd/compile: handle interface type parameters in type switches
Change-Id: I9bba21a64d7e9f42395b6fcdf8aa3ca01cf131dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/340912
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Diffstat (limited to 'test/typeparam/typeswitch6.go')
-rw-r--r-- | test/typeparam/typeswitch6.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/typeparam/typeswitch6.go b/test/typeparam/typeswitch6.go new file mode 100644 index 0000000000..574f4aa819 --- /dev/null +++ b/test/typeparam/typeswitch6.go @@ -0,0 +1,30 @@ +// 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 f[T any](i interface{}) { + switch i.(type) { + case T: + println("T") + case int: + println("int") + default: + println("other") + } +} + +type myint int +func (myint) foo() { +} + +func main() { + f[interface{}](nil) + f[interface{}](6) + f[interface{foo()}](nil) + f[interface{foo()}](7) + f[interface{foo()}](myint(8)) +} |