aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-11-17 15:23:12 -0800
committerRobert Griesemer <gri@golang.org>2021-11-24 20:57:46 +0000
commitc25bf0d959c299e5fa5392ae6f835570ed6d111f (patch)
tree023a9074b64e65a9629fc894e7487625e79b7e68 /test
parent9e7600d3fccf1920028bc808c755198db73482c0 (diff)
downloadgo-c25bf0d959c299e5fa5392ae6f835570ed6d111f.tar.gz
go-c25bf0d959c299e5fa5392ae6f835570ed6d111f.zip
cmd/compile/internal/types2: report types for mismatched call and return statements
Thanks to emmanuel@orijtech.com who wrote the initial version of this change (CL 354490). This change is following CL 354490 in idea but also contains various simplifications, slightly improved printing of signature/type patterns, adjustments for types2, and some fine-tuning of error positions. Also adjusted several ERROR regexp patterns. Fixes #48834. Fixes #48835. Change-Id: I31cf20c81753b1dc84836dbe83a39030ceb9db23 Reviewed-on: https://go-review.googlesource.com/c/go/+/364874 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/bug326.go2
-rw-r--r--test/fixedbugs/issue4215.go20
-rw-r--r--test/fixedbugs/issue46957.go2
-rw-r--r--test/fixedbugs/issue48834.go24
-rw-r--r--test/fixedbugs/issue48835.go25
5 files changed, 61 insertions, 12 deletions
diff --git a/test/fixedbugs/bug326.go b/test/fixedbugs/bug326.go
index dfd8be8005..74e06f39d7 100644
--- a/test/fixedbugs/bug326.go
+++ b/test/fixedbugs/bug326.go
@@ -19,7 +19,7 @@ func h() (_ int, _ error) {
}
func i() (int, error) {
- return // ERROR "not enough arguments to return|wrong number of return values"
+ return // ERROR "not enough return values|not enough arguments to return"
}
func f1() (_ int, err error) {
diff --git a/test/fixedbugs/issue4215.go b/test/fixedbugs/issue4215.go
index 7201591f3f..b6ece4bf21 100644
--- a/test/fixedbugs/issue4215.go
+++ b/test/fixedbugs/issue4215.go
@@ -7,7 +7,7 @@
package main
func foo() (int, int) {
- return 2.3 // ERROR "not enough arguments to return\n\thave \(number\)\n\twant \(int, int\)|not enough arguments to return|wrong number of return values"
+ return 2.3 // ERROR "not enough return values\n\thave \(number\)\n\twant \(int, int\)|not enough arguments to return"
}
func foo2() {
@@ -16,19 +16,19 @@ func foo2() {
func foo3(v int) (a, b, c, d int) {
if v >= 0 {
- return 1 // ERROR "not enough arguments to return\n\thave \(number\)\n\twant \(int, int, int, int\)|not enough arguments to return|wrong number of return values"
+ return 1 // ERROR "not enough return values\n\thave \(number\)\n\twant \(int, int, int, int\)|not enough arguments to return"
}
- return 2, 3 // ERROR "not enough arguments to return\n\thave \(number, number\)\n\twant \(int, int, int, int\)|not enough arguments to return|wrong number of return values"
+ return 2, 3 // ERROR "not enough return values\n\thave \(number, number\)\n\twant \(int, int, int, int\)|not enough arguments to return"
}
func foo4(name string) (string, int) {
switch name {
case "cow":
- return "moo" // ERROR "not enough arguments to return\n\thave \(string\)\n\twant \(string, int\)|not enough arguments to return|wrong number of return values"
+ return "moo" // ERROR "not enough return values\n\thave \(string\)\n\twant \(string, int\)|not enough arguments to return"
case "dog":
- return "dog", 10, true // ERROR "too many arguments to return\n\thave \(string, number, bool\)\n\twant \(string, int\)|too many values in return statement|wrong number of return values"
+ return "dog", 10, true // ERROR "too many return values\n\thave \(string, number, bool\)\n\twant \(string, int\)|too many arguments to return"
case "fish":
- return "" // ERROR "not enough arguments to return\n\thave \(string\)\n\twant \(string, int\)|not enough arguments to return|wrong number of return values"
+ return "" // ERROR "not enough return values\n\thave \(string\)\n\twant \(string, int\)|not enough arguments to return"
default:
return "lizard", 10
}
@@ -40,14 +40,14 @@ type U float64
func foo5() (S, T, U) {
if false {
- return "" // ERROR "not enough arguments to return\n\thave \(string\)\n\twant \(S, T, U\)|not enough arguments to return|wrong number of return values"
+ return "" // ERROR "not enough return values\n\thave \(string\)\n\twant \(S, T, U\)|not enough arguments to return"
} else {
ptr := new(T)
- return ptr // ERROR "not enough arguments to return\n\thave \(\*T\)\n\twant \(S, T, U\)|not enough arguments to return|wrong number of return values"
+ return ptr // ERROR "not enough return values\n\thave \(\*T\)\n\twant \(S, T, U\)|not enough arguments to return"
}
- return new(S), 12.34, 1 + 0i, 'r', true // ERROR "too many arguments to return\n\thave \(\*S, number, number, number, bool\)\n\twant \(S, T, U\)|too many values in return statement|wrong number of return values"
+ return new(S), 12.34, 1 + 0i, 'r', true // ERROR "too many return values\n\thave \(\*S, number, number, number, bool\)\n\twant \(S, T, U\)|too many arguments to return"
}
func foo6() (T, string) {
- return "T", true, true // ERROR "too many arguments to return\n\thave \(string, bool, bool\)\n\twant \(T, string\)|too many values in return statement|wrong number of return values"
+ return "T", true, true // ERROR "too many return values\n\thave \(string, bool, bool\)\n\twant \(T, string\)|too many arguments to return"
}
diff --git a/test/fixedbugs/issue46957.go b/test/fixedbugs/issue46957.go
index f3ed3c3def..6c1c0fe0c2 100644
--- a/test/fixedbugs/issue46957.go
+++ b/test/fixedbugs/issue46957.go
@@ -9,5 +9,5 @@ package main
func f(a int, b ...int) {}
func main() {
- f(nil...) // ERROR "not enough arguments in call to f$"
+ f(nil...) // ERROR "not enough arguments in call to f\n\thave \(nil\)\n\twant \(int, \[\]int\)|not enough arguments"
}
diff --git a/test/fixedbugs/issue48834.go b/test/fixedbugs/issue48834.go
new file mode 100644
index 0000000000..cf97d132c3
--- /dev/null
+++ b/test/fixedbugs/issue48834.go
@@ -0,0 +1,24 @@
+// 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 p
+
+func _() (int, error) {
+ return 1 // ERROR "not enough (arguments to return|return values)\n\thave \(number\)\n\twant \(int, error\)"
+}
+
+func _() (int, error) {
+ var x int
+ return x // ERROR "not enough (arguments to return|return values)\n\thave \(int\)\n\twant \(int, error\)"
+}
+
+func _() int {
+ return 1, 2 // ERROR "too many (arguments to return|return values)\n\thave \(number, number\)\n\twant \(int\)"
+}
+
+func _() {
+ return 1 // ERROR "too many arguments to return\n\thave \(number\)\n\twant \(\)|no result values expected"
+}
diff --git a/test/fixedbugs/issue48835.go b/test/fixedbugs/issue48835.go
new file mode 100644
index 0000000000..c000f8357d
--- /dev/null
+++ b/test/fixedbugs/issue48835.go
@@ -0,0 +1,25 @@
+// 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 p
+
+func f0()
+func f1(_ int)
+func f2(_, _ int)
+func f2ddd(_, _ int, _ ...int)
+
+func f() {
+ var x int
+ f0(1) // ERROR "too many arguments in call to f0\n\thave \(number\)\n\twant \(\)"
+ f0(x) // ERROR "too many arguments in call to f0\n\thave \(int\)\n\twant \(\)"
+ f1() // ERROR "not enough arguments in call to f1\n\thave \(\)\n\twant \(int\)"
+ f1(1, 2) // ERROR "too many arguments in call to f1\n\thave \(number, number\)\n\twant \(int\)"
+ f2(1) // ERROR "not enough arguments in call to f2\n\thave \(number\)\n\twant \(int, int\)"
+ f2(1, "foo", true) // ERROR "too many arguments in call to f2\n\thave \(number, string, bool\)\n\twant \(int, int\)"
+ f2ddd(1) // ERROR "not enough arguments in call to f2ddd\n\thave \(number\)\n\twant \(int, int, \.\.\.int\)"
+ f2ddd(1, 2)
+ f2ddd(1, 2, 3)
+}