Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

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

Open Quuxplusone opened 9 years ago

Quuxplusone commented 9 years ago
Bugzilla Link PR23585
Status NEW
Importance P normal
Reported by Tony Arnold (tony@thecocoabots.com)
Reported on 2015-05-19 19:16:33 -0700
Last modified on 2015-08-31 16:10:17 -0700
Version unspecified
Hardware PC All
CC djasper@google.com, klimek@google.com, ksuther@ithinksw.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
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)
Quuxplusone 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];
                         }];
Quuxplusone 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.