Skip to content

Commit fd4b587

Browse files
committed
cmd/compile: suppress details error for invalid variadic argument type
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>
1 parent e2e05af commit fd4b587

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/cmd/compile/internal/typecheck/typecheck.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,15 +1460,22 @@ toomany:
14601460
}
14611461

14621462
func errorDetails(nl ir.Nodes, tstruct *types.Type, isddd bool) string {
1463-
// If we don't know any type at a call site, let's suppress any return
1464-
// message signatures. See Issue https://golang.org/issues/19012.
1463+
// Suppress any return message signatures if:
1464+
//
1465+
// (1) We don't know any type at a call site (see #19012).
1466+
// (2) Any node has an unknown type.
1467+
// (3) Invalid type for variadic parameter (see #46957).
14651468
if tstruct == nil {
1466-
return ""
1469+
return "" // case 1
14671470
}
1468-
// If any node has an unknown type, suppress it as well
1471+
1472+
if isddd && !nl[len(nl)-1].Type().IsSlice() {
1473+
return "" // case 3
1474+
}
1475+
14691476
for _, n := range nl {
14701477
if n.Type() == nil {
1471-
return ""
1478+
return "" // case 2
14721479
}
14731480
}
14741481
return fmt.Sprintf("\n\thave %s\n\twant %v", fmtSignature(nl, isddd), tstruct)

test/fixedbugs/issue46957.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// errorcheck
2+
3+
// Copyright 2021 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
func f(a int, b ...int) {}
10+
11+
func main() {
12+
f(nil...) // ERROR "not enough arguments in call to f$"
13+
}

0 commit comments

Comments
 (0)