llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.16k stars 12.03k forks source link

Regression: Objective-C method calls are being broken over multiple lines when ColumnLimit: 0 #23959

Open llvmbot opened 9 years ago

llvmbot commented 9 years ago
Bugzilla Link 23585
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor

Extended Description

Something has changed recently with regards to Objective-C formatting that's causing ColumnLimit of 0 to be ignored. I see this at the top level of my classes, but first noticed it inside blocks.

Expected output:

[self registerAttributeForClass:class withKeyPaths:@[
    @"Something"
]];

Actual output:

[self registerAttributeForClass:class
                   withKeyPaths:@[
                        kIBAbatteryLevelKeyPath
                   ]];

This is present in clang-format version 3.7.0 (http://llvm.org/git/clang.git f52c3d239ef95ff0ff71800258f879d661c261c5) (http://llvm.org/git/llvm.git 4bc9d4ea2648db800f0d89adc73bd43e91fc6dcf)

llvmbot commented 9 years ago

The commit that introduced this issue is r235580 (clang-format: Support nested block formatting with ColumnLimit=0.)

Not setting BreakBeforeParameter to true if ColumnLimit is zero fixes the issue, but this commit explicitly introduced this change. I don't fully understand the logic behind the change. It seems that Tok->MustBreakBefore is always going to be true when encountering a "}]" at the end of a block inside of an Obj-C method call, which is going to always force a break before the parameter.

I can see this making sense if there's already a newline before the parameter with the block, but I don't think it should be always introducing newlines if the parameter isn't already on a separate line.

llvmbot commented 9 years ago

It seems there's something unusual happening here, too:

[self setupTextFieldSignals:@[ self.documentWidthField, self.documentHeightField, ] solver:^(NSTextField *textField) { return [self.representedObject solveEquationForTextField:textField]; }];

Gets reformatted to:

[self setupTextFieldSignals:@[
    self.documentWidthField,
    self.documentHeightField,
]
                     solver:^(NSTextField *textField) {
                         return [self.representedObject solveEquationForTextField:textField];
                     }];