Merge pull request #935 from nspcc-dev/fix/slice

compiler: support implicit type in function arguments
This commit is contained in:
Roman Khimov 2020-05-06 18:30:01 +03:00 committed by GitHub
commit a1d8206ef7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -249,10 +249,11 @@ func (c *codegen) convertFuncDecl(file ast.Node, decl *ast.FuncDecl) {
// Load the arguments in scope.
for _, arg := range decl.Type.Params.List {
name := arg.Names[0].Name // for now.
l := c.scope.newLocal(name)
for _, id := range arg.Names {
l := c.scope.newLocal(id.Name)
c.emitStoreLocal(l)
}
}
// Load in all the global variables in to the scope of the function.
// This is not necessary for syscalls.
if !isSyscall(f) {

View file

@ -158,3 +158,14 @@ func TestFunctionWithVoidReturnBranch(t *testing.T) {
eval(t, src, big.NewInt(2))
})
}
func TestFunctionWithMultipleArgumentNames(t *testing.T) {
src := `package foo
func Main() int {
return add(1, 2)
}
func add(a, b int) int {
return a + b
}`
eval(t, src, big.NewInt(3))
}