Skip to content

Commit 1a94431

Browse files
committed
cmd/cgo: support multiple-value special form in VarDecl
Fixes #13930. Change-Id: I124b7d31d1f2be05b7f23dafd1e52d9f3f02f3f0 Reviewed-on: https://go-review.googlesource.com/18623 Run-TryBot: Matthew Dempsky <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent a576e98 commit 1a94431

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

misc/cgo/test/issue13930.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2016 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Issue 13930. Test that cgo's multiple-value special form for
6+
// C function calls works in variable declaration statements.
7+
8+
package cgotest
9+
10+
// #include <stdlib.h>
11+
import "C"
12+
13+
var _, _ = C.abs(0)

src/cmd/cgo/ast.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,11 @@ func (f *File) walk(x interface{}, context string, visit func(*File, interface{}
447447
case *ast.ImportSpec:
448448
case *ast.ValueSpec:
449449
f.walk(&n.Type, "type", visit)
450-
f.walk(n.Values, "expr", visit)
450+
if len(n.Names) == 2 && len(n.Values) == 1 {
451+
f.walk(&n.Values[0], "as2", visit)
452+
} else {
453+
f.walk(n.Values, "expr", visit)
454+
}
451455
case *ast.TypeSpec:
452456
f.walk(&n.Type, "type", visit)
453457

src/cmd/cgo/doc.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ assignment context to retrieve both the return value (if any) and the
148148
C errno variable as an error (use _ to skip the result value if the
149149
function returns void). For example:
150150
151-
n, err := C.sqrt(-1)
151+
n, err = C.sqrt(-1)
152152
_, err := C.voidFunc()
153+
var n, err = C.sqrt(1)
153154
154155
Calling C function pointers is currently not supported, however you can
155156
declare Go variables which hold C function pointers and pass them

0 commit comments

Comments
 (0)