github.com/gocuntian/go@v0.0.0-20160610041250-fee02d270bf8/src/go/types/testdata/decls2b.src (about)

     1  // Copyright 2012 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // method declarations
     6  
     7  package decls2
     8  
     9  import "io"
    10  
    11  const pi = 3.1415
    12  
    13  func (T1) m /* ERROR "already declared" */ () {}
    14  func (T2) m(io.Writer) {}
    15  
    16  type T3 struct {
    17  	f *T3
    18  }
    19  
    20  type T6 struct {
    21  	x int
    22  }
    23  
    24  func (t *T6) m1() int {
    25  	return t.x
    26  }
    27  
    28  func f() {
    29  	var t *T6
    30  	t.m1()
    31  }
    32  
    33  // Double declarations across package files
    34  const c_double /* ERROR "redeclared" */ = 0
    35  type t_double  /* ERROR "redeclared" */ int
    36  var v_double /* ERROR "redeclared" */ int
    37  func f_double /* ERROR "redeclared" */ () {}
    38  
    39  // Blank methods need to be type-checked.
    40  // Verify by checking that errors are reported.
    41  func (T /* ERROR "undeclared" */ ) _() {}
    42  func (T1) _(undeclared /* ERROR "undeclared" */ ) {}
    43  func (T1) _() int { return "foo" /* ERROR "cannot convert" */ }
    44  
    45  // Methods with undeclared receiver type can still be checked.
    46  // Verify by checking that errors are reported.
    47  func (Foo /* ERROR "undeclared" */ ) m() {}
    48  func (Foo /* ERROR "undeclared" */ ) m(undeclared /* ERROR "undeclared" */ ) {}
    49  func (Foo /* ERROR "undeclared" */ ) m() int { return "foo" /* ERROR "cannot convert" */ }
    50  
    51  func (Foo /* ERROR "undeclared" */ ) _() {}
    52  func (Foo /* ERROR "undeclared" */ ) _(undeclared /* ERROR "undeclared" */ ) {}
    53  func (Foo /* ERROR "undeclared" */ ) _() int { return "foo" /* ERROR "cannot convert" */ }
    54  
    55  // Receiver declarations are regular parameter lists;
    56  // receiver types may use parentheses, and the list
    57  // may have a trailing comma.
    58  type T7 struct {}
    59  
    60  func (T7) m1() {}
    61  func ((T7)) m2() {}
    62  func ((*T7)) m3() {}
    63  func (x *(T7),) m4() {}
    64  func (x (*(T7)),) m5() {}
    65  func (x ((*((T7)))),) m6() {}