Skip to content

Commit 255b1cf

Browse files
authored
interp: do not allow function declaration without body
Such function declaration denotes either a linkname (an access to an arbitrary, typically unexported symbol, solved by go compiler), or a foreign C or assembly implementation of the body. Those cases are not supported (or planned to be) by the interpreter. Fixes #1431.
1 parent d3fc5e9 commit 255b1cf

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

interp/cfg.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ func (interp *Interpreter) cfg(root *node, sc *scope, importPath, pkgName string
360360
fallthrough
361361

362362
case funcDecl:
363+
// Do not allow function declarations without body.
364+
if len(n.child) < 4 {
365+
err = n.cfgErrorf("function declaration without body is unsupported (linkname or assembly can not be interpreted).")
366+
return false
367+
}
363368
n.val = n
364369
// Compute function type before entering local scope to avoid
365370
// possible collisions with function argument names.

interp/interp_eval_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ func TestEvalCall(t *testing.T) {
701701
{src: ` test := func(a, b int) int { return a }
702702
blah := func() (int, float64) { return 1, 1.1 }
703703
a := test(blah())`, err: "3:15: cannot use func() (int,float64) as type (int,int)"},
704+
{src: "func f()", err: "function declaration without body is unsupported"},
704705
})
705706
}
706707

0 commit comments

Comments
 (0)