reject_iface_arg_missing_method.mx raw

   1  // expected: does not implement fmt.Stringer (missing method String)
   2  //
   3  // A concrete value assigned to a non-empty interface must provide every method
   4  // the interface names. The checker skipped this direction because an
   5  // interface's method set may not be resolved yet, and the skip covered the
   6  // destination as well as the source: `take(xs)` with xs []int32 and
   7  // take(s fmt.Stringer) compiled, and the emitter rendered '?' for the value at
   8  // run time. Legacy reports "[]int32 does not implement fmt.Stringer (missing
   9  // method String)".
  10  //
  11  // The verdict runs in a package post-pass, not at the assignment: os.File.Stat
  12  // is declared in stat_unix.mx, after file.mx, so a method set read while the
  13  // earlier file is being built is missing methods that exist.
  14  package main
  15  
  16  import (
  17  	"fmt"
  18  )
  19  
  20  func take(s fmt.Stringer) (n int32) { return len(s.String()) }
  21  
  22  func main() {
  23  	xs := []int32{1, 2, 3}
  24  	println(take(xs))
  25  }
  26