]> Cypherpunks repositories - gostls13.git/commit
spec: clarify context type for certain non-constant shifts
authorgriesemer <gri@golang.org>
Wed, 30 Aug 2017 13:10:12 +0000 (15:10 +0200)
committerRobert Griesemer <gri@golang.org>
Fri, 1 Sep 2017 15:46:24 +0000 (15:46 +0000)
commit9690d245d56d547c40dac269140dcddc6eb80904
tree97bc3446c1c47b6bc549f3a715f2ed699bb62f7e
parentec359643a1f663c5283a81410f003f8dab60d46e
spec: clarify context type for certain non-constant shifts

The spec is not conclusive about whether a non-constant shift of
certain untyped constant left operands is valid when the shift
expression appears as an index in an index or slice expression,
or as a size in a `make` function call.

Despite identical spec rules in all these cases, cmd/compile accepts

make([]byte, 1.0 << s)

but pronounces an error for

a[1.0 << s]

(go/types accepts both).

This change clarifies the spec by explicitly stating that an
untyped constant left operand in a non-constant shift (1.0 in
the above examples) will be given type `int` in these contexts.

A separate issue #21693 addresses the cmd/compile bug.

Fixes #14844.

Change-Id: I4b52125e487a607fae377fcbed55463cdce9836c
Reviewed-on: https://go-review.googlesource.com/60230
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
doc/go_spec.html