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 <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>
This commit is contained in:
Robert Griesemer 2025-10-29 15:22:14 -07:00 committed by Gopher Robot
parent d2c5fa0814
commit 3be9a0e014
3 changed files with 31 additions and 0 deletions

View 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
}

View 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
}

View file

@ -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
}