]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: add test for interface type NumMethod
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 22 Mar 2023 04:44:04 +0000 (11:44 +0700)
committerGopher Robot <gobot@golang.org>
Wed, 22 Mar 2023 16:39:08 +0000 (16:39 +0000)
While at it, also use concrete type for non-interface type test.

Change-Id: Ie468c30ee31ba99ef8f9a810d3be851fd37b9b43
Reviewed-on: https://go-review.googlesource.com/c/go/+/478356
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
src/reflect/all_test.go

index c257bec1e589fbecf1e92bcaccd56edc3fa65980..31f6416ed9ac0aff89d8610c83547fc97e38dfec 100644 (file)
@@ -3281,14 +3281,16 @@ type unexpI interface {
        f() (int32, int8)
 }
 
-var unexpi unexpI = new(unexp)
-
 func TestUnexportedMethods(t *testing.T) {
-       typ := TypeOf(unexpi)
-
+       typ := TypeOf(new(unexp))
        if got := typ.NumMethod(); got != 0 {
                t.Errorf("NumMethod=%d, want 0 satisfied methods", got)
        }
+
+       typ = TypeOf((*unexpI)(nil))
+       if got := typ.Elem().NumMethod(); got != 1 {
+               t.Errorf("NumMethod=%d, want 1 satisfied methods", got)
+       }
 }
 
 type InnerInt struct {