Source file test/method2.go

     1  // errorcheck
     2  
     3  // Copyright 2009 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  // Verify that pointers and interface types cannot be method receivers.
     8  // Does not compile.
     9  
    10  package main
    11  
    12  type T struct {
    13  	a int
    14  }
    15  type P *T
    16  type P1 *T
    17  
    18  func (p P) val() int   { return 1 } // ERROR "receiver.* pointer|invalid pointer or interface receiver|invalid receiver"
    19  func (p *P1) val() int { return 1 } // ERROR "receiver.* pointer|invalid pointer or interface receiver|invalid receiver"
    20  
    21  type I interface{}
    22  type I1 interface{}
    23  
    24  func (p I) val() int   { return 1 } // ERROR "receiver.*interface|invalid pointer or interface receiver"
    25  func (p *I1) val() int { return 1 } // ERROR "receiver.*interface|invalid pointer or interface receiver"
    26  
    27  type Val interface {
    28  	val() int
    29  }
    30  
    31  var _ = (*Val).val // ERROR "method|type \*Val is pointer to interface, not interface"
    32  
    33  var v Val
    34  var pv = &v
    35  
    36  var _ = pv.val() // ERROR "undefined|pointer to interface"
    37  var _ = pv.val   // ERROR "undefined|pointer to interface"
    38  
    39  func (t *T) g() int { return t.a }
    40  
    41  var _ = (T).g() // ERROR "needs pointer receiver|undefined|method requires pointer|cannot call pointer method"
    42  

View as plain text