Menu

#464 Incorrect indentation of C# collection initialization

open-accepted
None
2023-08-29
2017-11-03
a9892b58
No

Source:

List<int> ints = new List<int>(count)
{
    MyClass.GetInt(0),
    MyClass.GetInt(2)
};

Current trunk:

List<int> ints = new List<int>(count)
{
    MyClass.GetInt(0),
                   MyClass.GetInt(2)
};

I attach a patch with a workaround I did locally to fix the issue.

1 Attachments

Discussion

  • Francois Botha

    Francois Botha - 2019-01-18

    Before I log a new issue, I want to check whether what I'm experiencing is related to this issue.

    I have this code and AStyle config:

       public class Sample
       {
          private static MyObject myObject = Initialize(DateTime.Today,
                                                        new List<double>() { 0.5, 0.7 },
                                                        String.Empty);
       }
    

    Notice that the parameters of Initialize are aligned.

    # braces and indent
    style=allman
    indent=spaces=3
    
    # indentation
    min-conditional-indent=0
    max-continuation-indent=80
    indent-classes
    indent-namespaces
    indent-switches
    
    # padding
    pad-oper
    pad-header
    unpad-paren
    align-pointer=type
    
    # formatting
    break-one-line-headers
    keep-one-line-blocks
    keep-one-line-statements
    convert-tabs
    
    # other options
    suffix=none
    exclude=obj
    

    I expect the code to remain unchanged, but the List<double> initializer messes something up. Output:

       public class Sample
       {
          private static MyObject myObject = Initialize(DateTime.Today,
          new List<double>() { 0.5, 0.7 },
          String.Empty);
       }
    
     
  • André Simon

    André Simon - 2023-05-10
    • status: open --> open-accepted
    • assigned_to: André Simon
     
  • André Simon

    André Simon - 2023-08-29
     
  • André Simon

    André Simon - 2023-08-29

    The first issue was fixed in 3.4.6

     

Log in to post a comment.