Skip to content

Commit 3be9a0e

Browse files
Robert Griesemergopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Robert Griesemer <[email protected]>
1 parent d2c5fa0 commit 3be9a0e

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/cmd/compile/internal/types2/call.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, def *TypeName
931931

932932
Error:
933933
x.mode = invalid
934+
x.typ = Typ[Invalid]
934935
x.expr = e
935936
}
936937

src/go/types/call.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, def *TypeName, w
979979

980980
Error:
981981
x.mode = invalid
982+
x.typ = Typ[Invalid]
982983
x.expr = e
983984
}
984985

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
func _() {
8+
f(foo /* ERROR "undefined: foo" */) // ERROR "not enough arguments in call to f\n\thave (unknown type)\n\twant (int, int)"
9+
}
10+
11+
func f(_, _ int) {}
12+
13+
// test case from issue
14+
15+
type S struct{}
16+
17+
func (S) G() {}
18+
19+
func main() {
20+
var s S
21+
_ = must(s.F /* ERROR "s.F undefined" */ ()) // ERROR "not enough arguments in call to must\n\thave (unknown type)\n\twant (T, error)"
22+
}
23+
24+
func must[T any](x T, err error) T {
25+
if err != nil {
26+
panic(err)
27+
}
28+
return x
29+
}

0 commit comments

Comments
 (0)