]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: name interface type that pins method info
authorDavid Crawshaw <crawshaw@golang.org>
Fri, 25 Mar 2016 15:03:47 +0000 (11:03 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Fri, 25 Mar 2016 17:19:03 +0000 (17:19 +0000)
I recently added TestUnexportedMethods which uses an interface type
to pin type information for an unexported method. But as written,
the interface type is not accessible to the reflect package.

You can imagine a future compiler optimization realizing that and
removing the type information for f. In fact, cl/20901 happens to
do that.

Change-Id: I1ddb67f50cb9b5737253b58f10545f3de652c29d
Reviewed-on: https://go-review.googlesource.com/21112
Reviewed-by: Michel Lespinasse <walken@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/reflect/all_test.go

index bb4592b3322cedc000fdd8ce452b5427caf4245d..b0a2608afbc2623d5d6dc5c47ca8d8821b4b350d 100644 (file)
@@ -2372,12 +2372,14 @@ type unexp struct{}
 func (*unexp) f() (int32, int8) { return 7, 7 }
 func (*unexp) g() (int64, int8) { return 8, 8 }
 
-func TestUnexportedMethods(t *testing.T) {
-       _ = (interface {
-               f() (int32, int8)
-       })(new(unexp))
+type unexpI interface {
+       f() (int32, int8)
+}
 
-       typ := TypeOf(new(unexp))
+var unexpi unexpI = new(unexp)
+
+func TestUnexportedMethods(t *testing.T) {
+       typ := TypeOf(unexpi)
 
        if typ.Method(0).Type == nil {
                t.Error("missing type for satisfied method 'f'")