THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

lang: funcs: Catch simple function api usage without types

In case a programmer makes a mistake and passes in a function using the
simple function API without a type or even without the entire value,
we'll now return a sensible error message and panic in init() instead of
requiring a test to catch this alone.
pull/639/head
James Shubin 2 months ago
parent
commit
887d374c53
  1. 6
      lang/funcs/simple/simple.go

6
lang/funcs/simple/simple.go

@ -42,6 +42,12 @@ func Register(name string, fn *types.FuncValue) {
if _, exists := RegisteredFuncs[name]; exists {
panic(fmt.Sprintf("a simple func named %s is already registered", name))
}
if fn == nil {
panic(fmt.Sprintf("simple func %s contains no function body", name))
}
if fn.T == nil {
panic(fmt.Sprintf("simple func %s contains a nil type signature", name))
}
RegisteredFuncs[name] = fn // store a copy for ourselves
// register a copy in the main function database

Loading…
Cancel
Save