bf68170c63
A user noticed that, given the input { S: "Hello World", Integer: 42, }, { S: " ", // an actual <tab> Integer: 42, }, gofmt would incorrectly format the code as { S: "Hello World", Integer: 42, }, { S: " ", // an actual <tab> Integer: 42, }, The problem was in the nodeSize method, used to get the printed length of a node before it's actually printed to the final buffer. The exprList method calls nodeSize to see if one expression in a list changes too drastically in size from the previous, which means the vertical alignment should be broken. It is worth noting that nodeSize only reports valid lengths if the node fits into a single line; otherwise, it returns a large number, larger than an "infinity" currently set to 1e6. However, the "does it fit in a single line" logic was broken; it checked if any of the to-be-printed characters is less than ' ', which does include '\n' and '\f' (the latter used by tabwriter as well), but also includes '\t', which would make nodeSize incorrectly conclude that our key-value expression with a tab does not fit into a single line. While here, make the testdata test cases run as sub-tests, as I used "-run TestRewrite/tabs.input" to help debug this. Fixes #51910. Change-Id: Ib7936e02652bc58f99772b06384ae271fddf09e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/404955 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> |
||
---|---|---|
.github | ||
api | ||
doc | ||
lib/time | ||
misc | ||
src | ||
test | ||
.gitattributes | ||
.gitignore | ||
AUTHORS | ||
codereview.cfg | ||
CONTRIBUTING.md | ||
CONTRIBUTORS | ||
LICENSE | ||
PATENTS | ||
README.md | ||
SECURITY.md |
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 3.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Download and Install
Binary Distributions
Official binary distributions are available at https://go.dev/dl/.
After downloading a binary release, visit https://go.dev/doc/install for installation instructions.
Install From Source
If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.
Contributing
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.