diff options
| author | Robert Griesemer <gri@golang.org> | 2017-11-30 15:47:46 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2017-12-01 20:39:50 +0000 |
| commit | 088a9ad543398fa6e656dd5e6f837fb07caada16 (patch) | |
| tree | 333ad7301504c7a85b0beefd92860efd608c69ee /src | |
| parent | aaccb3834c37a923659d1dc1004dcde94f04d871 (diff) | |
| download | go-088a9ad543398fa6e656dd5e6f837fb07caada16.tar.xz | |
cmd/compile: permit indices of certain non-constant shifts
Per the decision for #14844, index expressions that are non-constant
shifts where the LHS operand is representable as an int are now valid.
Fixes #21693.
Change-Id: Ifafad2c0c65975e0200ce7e28d1db210e0eacd9d
Reviewed-on: https://go-review.googlesource.com/81277
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/compile/internal/gc/typecheck.go | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index ec4db17b1c..5285cb22d9 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -243,21 +243,15 @@ func callrecvlist(l Nodes) bool { } // indexlit implements typechecking of untyped values as -// array/slice indexes. It is equivalent to defaultlit -// except for constants of numerical kind, which are acceptable -// whenever they can be represented by a value of type int. +// array/slice indexes. It is almost equivalent to defaultlit +// but also accepts untyped numeric values representable as +// value of type int (see also checkmake for comparison). // The result of indexlit MUST be assigned back to n, e.g. // n.Left = indexlit(n.Left) func indexlit(n *Node) *Node { - if n == nil || !n.Type.IsUntyped() { - return n + if n != nil && n.Type != nil && n.Type.Etype == TIDEAL { + return defaultlit(n, types.Types[TINT]) } - switch consttype(n) { - case CTINT, CTRUNE, CTFLT, CTCPLX: - n = defaultlit(n, types.Types[TINT]) - } - - n = defaultlit(n, nil) return n } @@ -3783,6 +3777,10 @@ func checkmake(t *types.Type, arg string, n *Node) bool { } // defaultlit is necessary for non-constants too: n might be 1.1<<k. + // TODO(gri) The length argument requirements for (array/slice) make + // are the same as for index expressions. Factor the code better; + // for instance, indexlit might be called here and incorporate some + // of the bounds checks done for make. n = defaultlit(n, types.Types[TINT]) return true |
