github.com/neugram/ng@v0.0.0-20180309130942-d472ff93d872/eval/testdata/error7.ng (about)

     1  import "errors"
     2  
     3  // Support error elisions on "interior" arguments in function calls.
     4  func concat(a, b string) string { return a + b }
     5  foobar := concat($$ echo -n foo $$, $$ echo -n bar $$)
     6  
     7  // Check that the first function call gets its error elided
     8  func multiError(errStr string) (error, error) { return errors.New(errStr), nil }
     9  func check(a, b, c error) {
    10      if a.Error() != "a" || b.Error() != "b" || c != nil {
    11          panic("wrong error elision applied")
    12      }
    13  }
    14  check(multiError("a"), multiError("b"))
    15  
    16  func emptyInterface(args ...interface{}) {
    17      if len(args) != 2 {
    18          panic("wrong number of args")
    19      }
    20  }
    21  // Error elision should not happen for interface{} parameters
    22  emptyInterface(multiError(""))
    23  emptyInterface($$ echo $$)
    24  
    25  // More error elision for interior args
    26  func f(x, y, z int) { }
    27  func g() (int, error) { return 0, nil }
    28  f(g(), 1, 2)
    29  f(g(), g(), g())
    30  
    31  if foobar == "foobar" {
    32      print("OK")
    33  }