]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: fix errors in recording type information
authorRebecca Stambler <rstambler@golang.org>
Thu, 9 Aug 2018 16:34:19 +0000 (12:34 -0400)
committerAlan Donovan <adonovan@google.com>
Thu, 9 Aug 2018 20:13:38 +0000 (20:13 +0000)
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>

src/go/types/api_test.go
src/go/types/assignments.go
src/go/types/call.go
src/go/types/expr.go

index 700fde92313c652d838014313ef138be08a51edd..1fe20794ea9341b5bc85785c3634ca10e4270a5c 100644 (file)
@@ -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
index 6adef3b40707c58c96b8930312668cfd57ef1075..27002f66994037121ac9c8cfb95b9d7efc3f0a91 100644 (file)
@@ -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 {
index 4e8544ad88cd683a1b8cf0c4a94edcc1b939ef2a..d5c196afe84637de8c0f6e8c5b210e9df571e1c1 100644 (file)
@@ -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
index 60ac4a33adaf83a14fde584f1bb62f263653bd9a..c1deaf8325aaf85177f254cec814ad73ae2d67dc 100644 (file)
@@ -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)