Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/gofmt: multiline function arguments are inconsistently indented #39586

Open
ijschwabacher opened this issue Jun 14, 2020 · 4 comments
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ijschwabacher
Copy link

What version of Go are you using (go version)?

The playground reports that it's using go1.14.3.

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

The playground hides this information.

What did you do?

Format a function call with multiline arguments:

f((some
    multiline
  arg),
  (another
    multiline
  arg))

https://play.golang.org/p/UefV4IrB2C2

What did you expect to see?

Each multiline argument's continuation lines to be indented the same amount:

f((some
    multiline
  arg),
  (another
    multiline
  arg))

What did you see instead?

The continuation lines of the multiline argument that starts on the same line as the function call are not indented, but the remaining arguments are:

f((some
  multiline
arg),
  (another
    multiline
  arg))
@ianlancetaylor
Copy link
Contributor

I don't see the indentation you describe. I see

    f((some
        multiline
        arg),
        (another
            multline
            arg))

This seems consistent even if it is odd in this example. Each continuation is indented one tab stop from the start of the sequence.

@ijschwabacher
Copy link
Author

Yes, that particular example was misleading because I meant for pieces of each arg to be internally indented (and "arg" behaves differently if it is a closing delimiter).

The case I'm trying to avoid is this:

f(s{
    x: 0,
},
    s{
        x: 1,
    },
)

which is confusing. Yes, I get that this is just what happens when the indentation of individual function args is independent of the indentation of the function arg list, but I don't see what would be harmed if, when a multiline arg starts on the first line of the function call and some other arg uses the function arg list's indentation, the continuation of the first multiline arg (and subsequent args following its indentation) were additionally indented by the function arg list's indentation.

So you would have this:

type s struct {
    x int
}

func f(ss ...s) {}

func main() {
    // This indentation remains the same
    f(s{
        x: 0,
    })

    // As does this
    f(s{
        x: 0,
    }, s{
        x: 1,
    })

    // The presence of the third argument starting on an indented line
    // causes the first two arguments' continuations to be indented
    f(s{
            x: 0,
        }, s{
            x: 1,
        },
        s{
            x: 2,
        },
    )
}

@andybons
Copy link
Member

@griesemer

@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 15, 2020
@andybons andybons added this to the Unplanned milestone Jun 15, 2020
@ijschwabacher
Copy link
Author

Given @ianlancetaylor 's example, it's worth thinking about whether this behavior (when the last line of the arg doesn't start with a closing delimiter) is desirable:

fmt.Println("Hello", fmt.Sprintf("%s %s %s",
    "world",
    "and",
    "goodbye!"), fmt.Sprintf("%s %s %s", "Still",
    "here",
    "though."),
    fmt.Sprintf("%s %s %s", "How",
        "about",
        "this?"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants