diff --git a/interp/cfg.go b/interp/cfg.go index 1fe6b2271..78af0c7dd 100644 --- a/interp/cfg.go +++ b/interp/cfg.go @@ -360,6 +360,11 @@ func (interp *Interpreter) cfg(root *node, sc *scope, importPath, pkgName string fallthrough case funcDecl: + // Do not allow function declarations without body. + if len(n.child) < 4 { + err = n.cfgErrorf("function declaration without body is unsupported (linkname or assembly can not be interpreted).") + return false + } n.val = n // Compute function type before entering local scope to avoid // possible collisions with function argument names. diff --git a/interp/interp_eval_test.go b/interp/interp_eval_test.go index cc5b5eab8..602cd133f 100644 --- a/interp/interp_eval_test.go +++ b/interp/interp_eval_test.go @@ -701,6 +701,7 @@ func TestEvalCall(t *testing.T) { {src: ` test := func(a, b int) int { return a } blah := func() (int, float64) { return 1, 1.1 } a := test(blah())`, err: "3:15: cannot use func() (int,float64) as type (int,int)"}, + {src: "func f()", err: "function declaration without body is unsupported"}, }) }