diff options
author | Rob Findley <rfindley@google.com> | 2021-04-28 10:35:53 -0400 |
---|---|---|
committer | Robert Findley <rfindley@google.com> | 2021-04-28 20:22:15 +0000 |
commit | 6082c05d8b4ab59e74204a3749629c8e6240b7b0 (patch) | |
tree | b1dc598d3147816558867f576c33e7c0dfb94fb2 /src/cmd/compile/internal/types2/api_test.go | |
parent | 414af503d7ec20cdfd6df23d5dee733401644ba3 (diff) | |
download | go-6082c05d8b4ab59e74204a3749629c8e6240b7b0.tar.gz go-6082c05d8b4ab59e74204a3749629c8e6240b7b0.zip |
go/types: better errors for invalid short var decls
This is a port of CL 312170 to go/types, adjusted to use go/ast and to
add error codes. go/parser already emits errors for non-identifiers on
the LHS of a short var decl, so a TODO is added to reconsider this
redundancy.
A new error code is added for repeated identifiers in short var decls.
This is a bit specific, but I considered it to be a unique kind of
error.
The x/tools tests for this port turned up a bug: the new logic failed to
call recordDef for blank identifiers. Patchset #2 contains the fix for
this bug, both in go/types and cmd/compile/internal/types2.
Change-Id: Ibdc40b8b4ad0e0696111d431682e1f1056fd5eeb
Reviewed-on: https://go-review.googlesource.com/c/go/+/314629
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/types2/api_test.go')
-rw-r--r-- | src/cmd/compile/internal/types2/api_test.go | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types2/api_test.go b/src/cmd/compile/internal/types2/api_test.go index c90f2e7510..873390c1e9 100644 --- a/src/cmd/compile/internal/types2/api_test.go +++ b/src/cmd/compile/internal/types2/api_test.go @@ -555,6 +555,7 @@ func TestDefsInfo(t *testing.T) { {`package p2; var x int`, `x`, `var p2.x int`}, {`package p3; type x int`, `x`, `type p3.x int`}, {`package p4; func f()`, `f`, `func p4.f()`}, + {`package p5; func f() int { x, _ := 1, 2; return x }`, `_`, `var _ int`}, // generic types must be sanitized // (need to use sufficiently nested types to provoke unexpanded types) |