Skip to content

Commit 79bf795

Browse files
stamblerreadonovan
authored andcommitted
go/types: fix errors in recording type information
In my previous change, I didn't use the correct functions for continuing to record type informations after errors. Change to using the correct functions, and add a comment to clarify in expr.go. Updates #22467 Change-Id: I66ebb636ceb2b994db652343430f0551db0050c3 Reviewed-on: https://go-review.googlesource.com/128835 Run-TryBot: Robert Griesemer <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 28cee70 commit 79bf795

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/go/types/api_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func mustTypecheck(t *testing.T, path, source string, info *Info) string {
4242
return pkg.Name()
4343
}
4444

45-
func maybeTypecheck(t *testing.T, path, source string, info *Info) string {
45+
func mayTypecheck(t *testing.T, path, source string, info *Info) string {
4646
fset := token.NewFileSet()
4747
f, err := parser.ParseFile(fset, path, source, 0)
4848
if f == nil { // ignore errors unless f is nil
@@ -265,7 +265,7 @@ func TestTypesInfo(t *testing.T) {
265265

266266
for _, test := range tests {
267267
info := Info{Types: make(map[ast.Expr]TypeAndValue)}
268-
name := maybeTypecheck(t, "TypesInfo", test.src, &info)
268+
name := mayTypecheck(t, "TypesInfo", test.src, &info)
269269

270270
// look for expression type
271271
var typ Type

src/go/types/assignments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func (check *Checker) shortVarDecl(pos token.Pos, lhs, rhs []ast.Expr) {
310310
check.recordDef(ident, obj)
311311
}
312312
} else {
313-
check.expr(&operand{}, lhs)
313+
check.useLHS(lhs)
314314
check.errorf(lhs.Pos(), "cannot declare %s", lhs)
315315
}
316316
if obj == nil {

src/go/types/call.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ func (check *Checker) call(x *operand, e *ast.CallExpr) exprKind {
3434
check.conversion(x, T)
3535
}
3636
default:
37-
for _, arg := range e.Args {
38-
check.expr(&operand{}, arg)
39-
}
37+
check.use(e.Args...)
4038
check.errorf(e.Args[n-1].Pos(), "too many arguments in conversion to %s", T)
4139
}
4240
x.expr = e

src/go/types/expr.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,8 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
10941094
continue
10951095
}
10961096
key, _ := kv.Key.(*ast.Ident)
1097+
// do all possible checks early (before exiting due to errors)
1098+
// so we don't drop information on the floor
10971099
check.expr(x, kv.Value)
10981100
if key == nil {
10991101
check.errorf(kv.Pos(), "invalid field name %s in struct literal", kv.Key)

0 commit comments

Comments
 (0)