]> Cypherpunks repositories - gostls13.git/commit
cmd/gofmt: normalize integer imaginary literals starting with 0
authorRobert Griesemer <gri@golang.org>
Thu, 14 Feb 2019 00:38:01 +0000 (16:38 -0800)
committerRobert Griesemer <gri@golang.org>
Tue, 19 Feb 2019 20:38:06 +0000 (20:38 +0000)
commitf8abdd6c8a6bb4882e708f87d1e83ba5f897aeff
tree58a39c0422ce5a6e67b2367b42f2139a40d241df
parent613f0a31445666cd573bf070309607e579b0b5c7
cmd/gofmt: normalize integer imaginary literals starting with 0

An 'i' suffix on an integer literal marks the integer literal as
a decimal integer imaginary value, even if the literal without the
suffix starts with a 0 and thus looks like an octal value:

0123i == 123i // != 0123 * 1i

This is at best confusing, and at worst a potential source of bugs.
It is always safe to rewrite such literals into the equivalent
literal without the leading 0.

This CL implements this normalization.

Change-Id: Ib77ad535f98b5be912ecbdec20ca1b472c1b4973
Reviewed-on: https://go-review.googlesource.com/c/162538
Run-TryBot: Robert Griesemer <gri@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/gofmt/gofmt.go
src/cmd/gofmt/testdata/go2numbers.golden
src/cmd/gofmt/testdata/go2numbers.input