]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: support multiple-value special form in VarDecl
authorMatthew Dempsky <mdempsky@google.com>
Wed, 13 Jan 2016 23:51:16 +0000 (15:51 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 18 Feb 2016 20:12:20 +0000 (20:12 +0000)
Fixes #13930.

Change-Id: I124b7d31d1f2be05b7f23dafd1e52d9f3f02f3f0
Reviewed-on: https://go-review.googlesource.com/18623
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
misc/cgo/test/issue13930.go [new file with mode: 0644]
src/cmd/cgo/ast.go
src/cmd/cgo/doc.go

diff --git a/misc/cgo/test/issue13930.go b/misc/cgo/test/issue13930.go
new file mode 100644 (file)
index 0000000..3a22459
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2016 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 13930.  Test that cgo's multiple-value special form for
+// C function calls works in variable declaration statements.
+
+package cgotest
+
+// #include <stdlib.h>
+import "C"
+
+var _, _ = C.abs(0)
index c3a24c2b76315ca6ad1439694d415e67888be997..4c5dc9a23d3adfc68f1615bdae7cd30d738223b7 100644 (file)
@@ -447,7 +447,11 @@ func (f *File) walk(x interface{}, context string, visit func(*File, interface{}
        case *ast.ImportSpec:
        case *ast.ValueSpec:
                f.walk(&n.Type, "type", visit)
-               f.walk(n.Values, "expr", visit)
+               if len(n.Names) == 2 && len(n.Values) == 1 {
+                       f.walk(&n.Values[0], "as2", visit)
+               } else {
+                       f.walk(n.Values, "expr", visit)
+               }
        case *ast.TypeSpec:
                f.walk(&n.Type, "type", visit)
 
index bd38a5c153b8e5aabee055a571572da580da25ae..8b4e2bfd58ee26ff6b600980c56257e768c97a56 100644 (file)
@@ -148,8 +148,9 @@ assignment context to retrieve both the return value (if any) and the
 C errno variable as an error (use _ to skip the result value if the
 function returns void).  For example:
 
-       n, err := C.sqrt(-1)
+       n, err = C.sqrt(-1)
        _, err := C.voidFunc()
+       var n, err = C.sqrt(1)
 
 Calling C function pointers is currently not supported, however you can
 declare Go variables which hold C function pointers and pass them