]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: fix "previous" position info for duplicate switch cases
authorMatthew Dempsky <mdempsky@google.com>
Mon, 5 Aug 2019 20:12:01 +0000 (13:12 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 27 Aug 2019 19:53:05 +0000 (19:53 +0000)
commitc302785df941f10a4350f895e0c48886b582e609
tree9a371c7f9851a239065d72aa1275d361472ef38b
parentc1df5187d007f205c31d96c8cb9c173a634a102a
cmd/compile: fix "previous" position info for duplicate switch cases

Because the Node AST represents references to declared objects (e.g.,
variables, packages, types, constants) by directly pointing to the
referred object, we don't have use-position info for these objects.

For switch statements with duplicate cases, we report back where the
first duplicate value appeared. However, due to the AST
representation, if the value was a declared constant, we mistakenly
reported the constant declaration position as the previous case
position.

This CL reports back against the 'case' keyword's position instead, if
there's no more precise information available to us.

It also refactors code to emit the same "previous at" error message
for duplicate values in map literals.

Thanks to Emmanuel Odeke for the test case.

Fixes #33460.

Change-Id: Iec69542ccd4aad594dde8df02d1b880a422c5622
Reviewed-on: https://go-review.googlesource.com/c/go/+/188901
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/swt.go
src/cmd/compile/internal/gc/typecheck.go
test/fixedbugs/issue33460.go [new file with mode: 0644]