Skip to content

Chained constructor call is not formatted correctly #1762

Open
@fejesjoco

Description

Describe the bug
When I use .callThisConstructor to have one constructor call another one, it looks formatting was forgotten.

To Reproduce

      TypeSpec.classBuilder("HelloWorld")
        .addFunction(
          FunSpec.constructorBuilder()
            .addParameter("x".repeat(30), String::class)
            .addParameter("y".repeat(30), String::class)
            .callThisConstructor(
              CodeBlock.of("x".repeat(30)),
              CodeBlock.of("y".repeat(30)),
              CodeBlock.of("x".repeat(30)),
              CodeBlock.of("y".repeat(30)),
              buildCodeBlock {
                beginControlFlow("thisIsAMethodThatUsesALambdaAndReturnsSomethingForTheConstructor")
                addStatement("z".repeat(30) + "()")
                endControlFlow()
              }
            )
            .build()
        )
        .build()
    )
    .build()
    .writeTo(System.out)

This prints:

package com.test

import kotlin.String

public class HelloWorld {
  public constructor(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: String, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: String)
      : this(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
      xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
      thisIsAMethodThatUsesALambdaAndReturnsSomethingForTheConstructor {
    zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz()
  }
  )
}

If this() is counted as the 1st line, then the 2nd and 3rd lines are aligned vertically with the colon but they should be more indented than that, because the this() call opened a new nesting level like it was a statement call. And what follows inside the method call in the 4th and 5th lines should be indented even more but it's actually going backwards.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions