reject_unknown_iface_method.mx raw

   1  // expected: has no field or method Bytes
   2  //
   3  // An interface's method set is written down in the interface itself, so a
   4  // name that is not in it is always an error. stage4 skipped interfaces in
   5  // reportUndefinedField (a type parameter's methods live in an unresolved
   6  // constraint, an interface's do not) and buildIfaceMethodCall emitted the
   7  // invoke BEFORE looking the method up and then used "no result type" as its
   8  // not-a-method-call signal - which is also how a void method reports itself.
   9  // The call therefore evaluated to nil: `len(i.Bytes())` printed 0.
  10  // Legacy reports "i.Bytes undefined (type I2 has no field or method Bytes)".
  11  package main
  12  
  13  type I2 interface {
  14  	Equal(x I2) (ok bool)
  15  }
  16  
  17  type Only struct {
  18  	b []byte
  19  }
  20  
  21  func (o *Only) Equal(x I2) (ok bool) { return true }
  22  
  23  func main() {
  24  	o := Only{b: []byte{1, 2, 3}}
  25  	var i I2 = &o
  26  	_ = i.Equal(i)
  27  	_ = i.Bytes()
  28  }
  29