reject_instantiated_receiver.mx raw

   1  // expected: method receiver must name the type's type parameters
   2  //
   3  // A method goes on the defined generic type, with a receiver that names its
   4  // type parameters: func (t *table[K, V]) scan(). A receiver that carries an
   5  // INSTANTIATION - func (t *table[string, *node]) scan() - is not a method
   6  // declaration: the field offsets of a generic type are only known per
   7  // instantiation, and Go rejects it for the same reason ("receiver type
   8  // parameter *node must be an identifier").
   9  package main
  10  
  11  type pair[K comparable, V comparable] struct {
  12  	key   K
  13  	value V
  14  }
  15  
  16  type table[K comparable, V comparable] struct {
  17  	rows []pair[K, V]
  18  }
  19  
  20  type node struct {
  21  	name string
  22  	hits int32
  23  }
  24  
  25  func (t *table[string, *node]) scan(want string) (name string, hits int32) {
  26  	return
  27  }
  28  
  29  func main() {
  30  	select {
  31  	case <-shutdown:
  32  		return
  33  	default:
  34  	}
  35  	var t *table[string, *node]
  36  	name, _ := t.scan("x")
  37  	println(name)
  38  }
  39