From 887d374c530915565b0257e6ac6f8c0cda232067 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 28 Feb 2021 22:50:51 -0500 Subject: [PATCH] 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. --- lang/funcs/simple/simple.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lang/funcs/simple/simple.go b/lang/funcs/simple/simple.go index bea07b2f..aab2ee94 100644 --- a/lang/funcs/simple/simple.go +++ b/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