MCPcopy Index your code
hub / github.com/expr-lang/expr / ExampleWarnOnAny

Function ExampleWarnOnAny

expr_test.go:367–376  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

365}
366
367func 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
378func ExampleOperator() {
379 code := `

Callers

nothing calls this directly

Calls 4

CompileFunction · 0.92
AsIntFunction · 0.92
WarnOnAnyFunction · 0.92
PrintfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…