aboutsummaryrefslogtreecommitdiff
path: root/test/typeparam
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-07-02 16:59:01 -0700
committerMatthew Dempsky <mdempsky@google.com>2021-07-26 18:43:12 +0000
commitbfcb7c4c8adadd6191c3fdacf2b59136b0da5c1c (patch)
tree24731ce99b2df34efd2c3b64e2710347f35818d3 /test/typeparam
parentb27c7e30dc5d222766057e62c16cb765b636d244 (diff)
downloadgo-bfcb7c4c8adadd6191c3fdacf2b59136b0da5c1c.tar.gz
go-bfcb7c4c8adadd6191c3fdacf2b59136b0da5c1c.zip
[dev.typeparams] cmd/compile: fix unified IR support for //go:nointerface
This CL changes fixedbugs/issue30862.go into a "runindir" test so that it can use '-goexperiment fieldtrack' and test that //go:nointerface works with cmd/compile. In particular, this revealed that -G=3 and unified IR did not handle it correctly. This CL also fixes unified IR's support for //go:nointerface and adds a test that checks that //go:nointerface, promoted methods, and generics all interact as expected. Updates #47045. Change-Id: Ib8acff8ae18bf124520d00c98e8915699cba2abd Reviewed-on: https://go-review.googlesource.com/c/go/+/332611 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'test/typeparam')
-rw-r--r--test/typeparam/mdempsky/15.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/typeparam/mdempsky/15.go b/test/typeparam/mdempsky/15.go
new file mode 100644
index 0000000000..4899fc75ee
--- /dev/null
+++ b/test/typeparam/mdempsky/15.go
@@ -0,0 +1,69 @@
+// run -goexperiment fieldtrack -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.
+
+// Test that generics, promoted methods, and //go:nointerface
+// interoperate as expected.
+
+package main
+
+import (
+ "reflect"
+)
+
+func TypeString[T any]() string {
+ return reflect.TypeOf(new(T)).Elem().String()
+}
+
+func Test[T, Bad, Good any]() {
+ switch interface{}(new(T)).(type) {
+ case Bad:
+ println("FAIL:", TypeString[T](), "matched", TypeString[Bad]())
+ case Good:
+ // ok
+ default:
+ println("FAIL:", TypeString[T](), "did not match", TypeString[Good]())
+ }
+}
+
+func TestE[T any]() { Test[T, interface{ EBad() }, interface{ EGood() }]() }
+func TestX[T any]() { Test[T, interface{ XBad() }, interface{ XGood() }]() }
+
+type E struct{}
+
+//go:nointerface
+func (E) EBad() {}
+func (E) EGood() {}
+
+type X[T any] struct{ E }
+
+//go:nointerface
+func (X[T]) XBad() {}
+func (X[T]) XGood() {}
+
+type W struct{ X[int] }
+
+func main() {
+ _ = E.EGood
+ _ = E.EBad
+
+ TestE[E]()
+
+ _ = X[int].EGood
+ _ = X[int].EBad
+ _ = X[int].XGood
+ _ = X[int].XBad
+
+ TestE[X[int]]()
+ TestX[X[int]]()
+
+ _ = W.EGood
+ _ = W.EBad
+ _ = W.XGood
+ _ = W.XBad
+
+ TestE[W]()
+ TestX[W]()
+}