Skip to content

Keep a tabular array initializer with mixed signs in rows - #69

Merged
abashev merged 1 commit into
mainfrom
tabular-mixed-sign-initializer
Sep 25, 2026
Merged

abashev merged 1 commit into
mainfrom
tabular-mixed-sign-initializer

Conversation

@abashev

@abashev abashev commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Brings over google/google-java-format#406 by Andrew Reid, which fixes google/google-java-format#400 (google-java-format 1.8).

The bug

An array initializer written in rows, such as a table of coordinates, keeps its rows when every column holds expressions of the same kind. A column that mixed 95.0 with -95.0 or +95.0 did not count as one kind, because a signed number is a unary expression in javac's tree, so the whole table collapsed into one line:

    private static final double[] g = {95.0, 75.0, -95.0, 75.0, -95.0, 75.0, +95.0, 75.0};

while the same table without signs kept its two rows.

From upstream, with the author kept

Checked

  • The golden fails on main and passes with the change.
  • ./gradlew :open-java-format:test on JDK 21: 1501 tests, all green.
  • The 15,747 files of the JDK 21 sources format exactly as before.

An array initializer written in rows, such as a table of coordinates,
keeps its rows when every column holds expressions of the same kind.
A column that mixed 95.0 with -95.0 or +95.0 did not count as one kind,
because a signed number is a unary expression in javac's tree, so the
whole table collapsed into one line, or into a filled block.

This ports google/google-java-format#406 by Andrew Reid, which fixes
google/google-java-format#400: a unary expression counts as the kind
of its operand for that comparison. The golden
TabularMixedSignInitializer comes from upstream, with the expected
output in this project's style.

The 15,747 files of the JDK 21 sources format exactly as before.
@abashev
abashev merged commit 1760d93 into main Sep 25, 2026
15 checks passed
@abashev
abashev deleted the tabular-mixed-sign-initializer branch September 25, 2026 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatting of tabular array initializer confused by negative numbers

2 participants