reject_unknown_method_generic.mx raw

   1  // expected: has no field or method
   2  //
   3  // A method that does not exist on the element of an instantiated generic must
   4  // still be rejected. Resolving the forward-declared generic's field type (see
   5  // should_compile/generic_forward_field.mx) must not turn a missing method into
   6  // a call the compiler silently drops.
   7  package main
   8  
   9  type mapping[K comparable, V comparable] struct {
  10  	s []entry[K, V]
  11  }
  12  
  13  type entry[K comparable, V comparable] struct {
  14  	key   K
  15  	value V
  16  }
  17  
  18  type node struct {
  19  	name string
  20  }
  21  
  22  func (n *node) match(want string) (got *node, ok bool) {
  23  	return nil, false
  24  }
  25  
  26  type tree struct {
  27  	children mapping[string, *node]
  28  }
  29  
  30  func (t *tree) scan(want string) (n int32) {
  31  	for _, e := range t.children.s {
  32  		mp, _ := e.value.mismatch(want)
  33  		if mp != nil {
  34  			n = n + 1
  35  		}
  36  	}
  37  	return n
  38  }
  39  
  40  func main() {
  41  	t := &tree{}
  42  	t.children.s = []entry[string, *node]{}
  43  	t.scan("a")
  44  }
  45