...

Source file src/internal/types/testdata/check/decls2/decls2b.go

Documentation: internal/types/testdata/check/decls2

     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 "undefined" */ ) _() {}
    42  func (T1) _(undefined /* ERROR "undefined" */ ) {}
    43  func (T1) _() int { return "foo" /* ERRORx "cannot use .* in return statement" */ }
    44  
    45  // Methods with undefined receiver type can still be checked.
    46  // Verify by checking that errors are reported.
    47  func (Foo /* ERROR "undefined" */ ) m() {}
    48  func (Foo /* ERROR "undefined" */ ) m(undefined /* ERROR "undefined" */ ) {}
    49  func (Foo /* ERRORx `undefined` */ ) m() int { return "foo" /* ERRORx "cannot use .* in return statement" */ }
    50  
    51  func (Foo /* ERROR "undefined" */ ) _() {}
    52  func (Foo /* ERROR "undefined" */ ) _(undefined /* ERROR "undefined" */ ) {}
    53  func (Foo /* ERROR "undefined" */ ) _() int { return "foo" /* ERRORx "cannot use .* in return statement" */ }
    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() {}
    66  
    67  // Check that methods with parenthesized receiver are actually present (issue #23130).
    68  var (
    69  	_ = T7.m1
    70  	_ = T7.m2
    71  	_ = (*T7).m3
    72  	_ = (*T7).m4
    73  	_ = (*T7).m5
    74  	_ = (*T7).m6
    75  )
    76  

View as plain text