]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types: proceed with correct (invalid) type in case of a selector error
authorRobert Griesemer <gri@google.com>
Wed, 29 Oct 2025 22:22:14 +0000 (15:22 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 30 Oct 2025 02:16:42 +0000 (19:16 -0700)
Fixes #76103.

Change-Id: Idc2f5d1d7aeb4a9b468e7c268e3bf5b85d1c3777
Reviewed-on: https://go-review.googlesource.com/c/go/+/716300
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Griesemer <gri@google.com>

src/cmd/compile/internal/types2/call.go
src/go/types/call.go
src/internal/types/testdata/fixedbugs/issue76103.go [new file with mode: 0644]

index 7128ad78668e9ba64be1143a92cc1b5e705da9d4..52dc33b8cd5bfef32c369a5a3ae07b25ca51b6da 100644 (file)
@@ -931,6 +931,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, def *TypeName
 
 Error:
        x.mode = invalid
+       x.typ = Typ[Invalid]
        x.expr = e
 }
 
index 98498763c82516945d030baaf8375eda4ecb404c..3bc1a39ddcfa64bf1ca403045b4d94608fde283a 100644 (file)
@@ -979,6 +979,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, def *TypeName, w
 
 Error:
        x.mode = invalid
+       x.typ = Typ[Invalid]
        x.expr = e
 }
 
diff --git a/src/internal/types/testdata/fixedbugs/issue76103.go b/src/internal/types/testdata/fixedbugs/issue76103.go
new file mode 100644 (file)
index 0000000..6ba0d3c
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright 2025 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 _() {
+       f(foo /* ERROR "undefined: foo" */) // ERROR "not enough arguments in call to f\n\thave (unknown type)\n\twant (int, int)"
+}
+
+func f(_, _ int) {}
+
+// test case from issue
+
+type S struct{}
+
+func (S) G() {}
+
+func main() {
+       var s S
+       _ = must(s.F /* ERROR "s.F undefined" */ ()) // ERROR "not enough arguments in call to must\n\thave (unknown type)\n\twant (T, error)"
+}
+
+func must[T any](x T, err error) T {
+       if err != nil {
+               panic(err)
+       }
+       return x
+}