aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Stambler <rstambler@golang.org>2018-08-09 12:34:19 -0400
committerAlan Donovan <adonovan@google.com>2018-08-09 20:13:38 +0000
commit79bf7955dc225a8d5b28d8201b90aa0d6b0644aa (patch)
treedd252231d8b5ba988ea580379a4a6782c6616a8f
parent28cee7075e3a2eda9504c73ad4649ffcc01b52a4 (diff)
downloadgo-79bf7955dc225a8d5b28d8201b90aa0d6b0644aa.tar.gz
go-79bf7955dc225a8d5b28d8201b90aa0d6b0644aa.zip
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 <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/go/types/api_test.go4
-rw-r--r--src/go/types/assignments.go2
-rw-r--r--src/go/types/call.go4
-rw-r--r--src/go/types/expr.go2
4 files changed, 6 insertions, 6 deletions
diff --git a/src/go/types/api_test.go b/src/go/types/api_test.go
index 700fde9231..1fe20794ea 100644
--- a/src/go/types/api_test.go
+++ b/src/go/types/api_test.go
@@ -42,7 +42,7 @@ func mustTypecheck(t *testing.T, path, source string, info *Info) string {
return pkg.Name()
}
-func maybeTypecheck(t *testing.T, path, source string, info *Info) string {
+func mayTypecheck(t *testing.T, path, source string, info *Info) string {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, path, source, 0)
if f == nil { // ignore errors unless f is nil
@@ -265,7 +265,7 @@ func TestTypesInfo(t *testing.T) {
for _, test := range tests {
info := Info{Types: make(map[ast.Expr]TypeAndValue)}
- name := maybeTypecheck(t, "TypesInfo", test.src, &info)
+ name := mayTypecheck(t, "TypesInfo", test.src, &info)
// look for expression type
var typ Type
diff --git a/src/go/types/assignments.go b/src/go/types/assignments.go
index 6adef3b407..27002f6699 100644
--- a/src/go/types/assignments.go
+++ b/src/go/types/assignments.go
@@ -310,7 +310,7 @@ func (check *Checker) shortVarDecl(pos token.Pos, lhs, rhs []ast.Expr) {
check.recordDef(ident, obj)
}
} else {
- check.expr(&operand{}, lhs)
+ check.useLHS(lhs)
check.errorf(lhs.Pos(), "cannot declare %s", lhs)
}
if obj == nil {
diff --git a/src/go/types/call.go b/src/go/types/call.go
index 4e8544ad88..d5c196afe8 100644
--- a/src/go/types/call.go
+++ b/src/go/types/call.go
@@ -34,9 +34,7 @@ func (check *Checker) call(x *operand, e *ast.CallExpr) exprKind {
check.conversion(x, T)
}
default:
- for _, arg := range e.Args {
- check.expr(&operand{}, arg)
- }
+ check.use(e.Args...)
check.errorf(e.Args[n-1].Pos(), "too many arguments in conversion to %s", T)
}
x.expr = e
diff --git a/src/go/types/expr.go b/src/go/types/expr.go
index 60ac4a33ad..c1deaf8325 100644
--- a/src/go/types/expr.go
+++ b/src/go/types/expr.go
@@ -1094,6 +1094,8 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
continue
}
key, _ := kv.Key.(*ast.Ident)
+ // do all possible checks early (before exiting due to errors)
+ // so we don't drop information on the floor
check.expr(x, kv.Value)
if key == nil {
check.errorf(kv.Pos(), "invalid field name %s in struct literal", kv.Key)