()
| 365 | } |
| 366 | |
| 367 | func ExampleWarnOnAny() { |
| 368 | // Arrays always have []any type. The expression return type is any. |
| 369 | // AsInt() instructs compiler to expect int or any, and cast to int, |
| 370 | // if possible. WarnOnAny() instructs to return an error on any type. |
| 371 | _, err := expr.Compile(`[42, true, "yes"][0]`, expr.AsInt(), expr.WarnOnAny()) |
| 372 | |
| 373 | fmt.Printf("%v", err) |
| 374 | |
| 375 | // Output: expected int, but got interface {} |
| 376 | } |
| 377 | |
| 378 | func ExampleOperator() { |
| 379 | code := ` |