]> Cypherpunks.ru repositories - gostls13.git/blob - test/method7.go
[dev.boringcrypto] all: merge master into dev.boringcrypto
[gostls13.git] / test / method7.go
1 // run
2
3 // Copyright 2017 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 // Test forms of method expressions T.m where T is
8 // a literal type.
9
10 package main
11
12 var got, want string
13
14 type I interface {
15         m()
16 }
17
18 type S struct {
19 }
20
21 func (S) m()          { got += " m()" }
22 func (S) m1(s string) { got += " m1(" + s + ")" }
23
24 type T int
25
26 func (T) m2() { got += " m2()" }
27
28 func main() {
29         // method expressions with named receiver types
30         I.m(S{})
31         want += " m()"
32
33         S.m1(S{}, "a")
34         want += " m1(a)"
35
36         // method expressions with literal receiver types
37         f := interface{ m1(string) }.m1
38         f(S{}, "b")
39         want += " m1(b)"
40
41         interface{ m1(string) }.m1(S{}, "c")
42         want += " m1(c)"
43
44         x := S{}
45         interface{ m1(string) }.m1(x, "d")
46         want += " m1(d)"
47
48         g := struct{ T }.m2
49         g(struct{ T }{})
50         want += " m2()"
51
52         if got != want {
53                 panic("got" + got + ", want" + want)
54         }
55 }