-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
go/printer: match indentation when returning multiple composite literals #7195
Comments
@dsymonds - Just to clarify - you expected something like this ? func f() (*T, *T) {
return &T{
x: 1,
y: "foo",
}, &T{
x: 2,
y: "bar",
}
} i.e. one less indent when arranging the composite literals. |
Yes, I'd expect those two closing braces for the &T literals to be at the same indentation as the package main
type T struct {
x int
y string
}
func f() (*T, *T) {
// Declaring a looks right.
a := &T{
x: 1,
y: "foo",
}
// Returning a single composite literal looks right.
return &T{
x: 1,
y: "foo",
}
// Returning multiple values looks wrong
return &T{
x: 1,
y: "foo",
}, &T{
x: 2,
y: "bar",
}
} |
Analysis: This is due to the indentList() function in go/printer/nodes.go L1229. If that function returns false, then the literals line up as intended. And looking at the comment, it seems to be intentionally written to solve issue #1207 (which was incidentally filed by @dsymonds yourself :)).
The difference appears if the element is itself a composite literal or not. For example, if that function returns false, this issue is solved. But issue 1207 breaks. Breaks - return &T{
x: 1,
y: "foo",
},
nil Fixes- return &T{
x: 1,
y: "foo",
}, &T{
x: 2,
y: "bar",
} Will leave it to @griesemer to take a final call if we want to add more heuristic to check if the elements are composite literals or not. |
The text was updated successfully, but these errors were encountered: