From 3be9a0e014ee56f25ce4aac6091c617799fd26f2 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 29 Oct 2025 15:22:14 -0700 Subject: [PATCH] go/types, types: proceed with correct (invalid) type in case of a selector error Fixes #76103. Change-Id: Idc2f5d1d7aeb4a9b468e7c268e3bf5b85d1c3777 Reviewed-on: https://go-review.googlesource.com/c/go/+/716300 Reviewed-by: Robert Griesemer Reviewed-by: Alan Donovan LUCI-TryBot-Result: Go LUCI Auto-Submit: Robert Griesemer --- src/cmd/compile/internal/types2/call.go | 1 + src/go/types/call.go | 1 + .../types/testdata/fixedbugs/issue76103.go | 29 +++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 src/internal/types/testdata/fixedbugs/issue76103.go diff --git a/src/cmd/compile/internal/types2/call.go b/src/cmd/compile/internal/types2/call.go index 7128ad7866..52dc33b8cd 100644 --- a/src/cmd/compile/internal/types2/call.go +++ b/src/cmd/compile/internal/types2/call.go @@ -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 } diff --git a/src/go/types/call.go b/src/go/types/call.go index 98498763c8..3bc1a39ddc 100644 --- a/src/go/types/call.go +++ b/src/go/types/call.go @@ -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 index 0000000000..6ba0d3c677 --- /dev/null +++ b/src/internal/types/testdata/fixedbugs/issue76103.go @@ -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 +} -- 2.52.0