cmd/compile: don't report not enough args error if call is undefined

Fixes #38745

Change-Id: I2fbd8b512a8cf911b81a087162c74416116efea5
Reviewed-on: https://go-review.googlesource.com/c/go/+/253678
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go
index dec4b96..fb169cf 100644
--- a/src/cmd/compile/internal/gc/typecheck.go
+++ b/src/cmd/compile/internal/gc/typecheck.go
@@ -2667,7 +2667,7 @@
 	return
 
 notenough:
-	if n == nil || !n.Diag() {
+	if n == nil || (!n.Diag() && n.Type != nil) {
 		details := errorDetails(nl, tstruct, isddd)
 		if call != nil {
 			// call is the expression being called, not the overall call.
diff --git a/test/ddd1.go b/test/ddd1.go
index 2c7e83e..9857814 100644
--- a/test/ddd1.go
+++ b/test/ddd1.go
@@ -29,7 +29,7 @@
 	_ = sum(tuple())
 	_ = sum(tuple()...) // ERROR "multiple-value"
 	_ = sum3(tuple())
-	_ = sum3(tuple()...) // ERROR "multiple-value" "not enough"
+	_ = sum3(tuple()...) // ERROR "multiple-value"
 )
 
 type T []T
diff --git a/test/fixedbugs/issue38745.go b/test/fixedbugs/issue38745.go
index 21bd1ff..83a3bc6 100644
--- a/test/fixedbugs/issue38745.go
+++ b/test/fixedbugs/issue38745.go
@@ -14,6 +14,5 @@
 }
 
 func f2() (*t, error) {
-	// BAD: should report undefined error only.
-	return t{}.M() // ERROR "t{}.M undefined \(type t has no field or method M\)" "not enough arguments to return"
+	return t{}.M() // ERROR "t{}.M undefined \(type t has no field or method M\)"
 }