]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: suppress details error for invalid variadic argument type
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 29 Jun 2021 03:11:31 +0000 (10:11 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 29 Jun 2021 04:38:12 +0000 (04:38 +0000)
CL 255241 made error message involving variadic calls clearer. To do it,
we added a check that the type of variadic argument must be a slice.
That's why the compiler crashes for invalid variadic argument type.

Instead, we can just omit the details error message, and report not
enough arguments error, which matches the behavior of go/types and types2.

Fixes #46957

Change-Id: I638d7e8f031f0ee344d5d802104fd93a60aae00a
Reviewed-on: https://go-review.googlesource.com/c/go/+/331569
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/typecheck/typecheck.go
test/fixedbugs/issue46957.go [new file with mode: 0644]

index bf52941b2cfc6143fe45891934cfdfb8b11481ed..359f66236969fb4e34867ba35ea9d56b9480f5ba 100644 (file)
@@ -1460,15 +1460,22 @@ toomany:
 }
 
 func errorDetails(nl ir.Nodes, tstruct *types.Type, isddd bool) string {
-       // If we don't know any type at a call site, let's suppress any return
-       // message signatures. See Issue https://golang.org/issues/19012.
+       // Suppress any return message signatures if:
+       //
+       // (1) We don't know any type at a call site (see #19012).
+       // (2) Any node has an unknown type.
+       // (3) Invalid type for variadic parameter (see #46957).
        if tstruct == nil {
-               return ""
+               return "" // case 1
        }
-       // If any node has an unknown type, suppress it as well
+
+       if isddd && !nl[len(nl)-1].Type().IsSlice() {
+               return "" // case 3
+       }
+
        for _, n := range nl {
                if n.Type() == nil {
-                       return ""
+                       return "" // case 2
                }
        }
        return fmt.Sprintf("\n\thave %s\n\twant %v", fmtSignature(nl, isddd), tstruct)
diff --git a/test/fixedbugs/issue46957.go b/test/fixedbugs/issue46957.go
new file mode 100644 (file)
index 0000000..f3ed3c3
--- /dev/null
@@ -0,0 +1,13 @@
+// errorcheck
+
+// Copyright 2021 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.
+
+package main
+
+func f(a int, b ...int) {}
+
+func main() {
+       f(nil...) // ERROR "not enough arguments in call to f$"
+}