Skip to content

Commit

Permalink
format slice2.gop
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Oct 1, 2021
1 parent 36494ec commit ccdad99
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
12 changes: 6 additions & 6 deletions parser/_testdata/slice2/slice2.gop
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

func main() {
a := [
1,
2,
3,
]
println(a)
a := [
1,
2,
3,
]
println(a)
}
4 changes: 2 additions & 2 deletions printer/gop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func diffBytes(t *testing.T, dst, src []byte) {
d := dst[i]
s := src[i]
if d != s {
t.Errorf("dst:%d: %s\n", line, dst[offs:i+5])
t.Errorf("src:%d: %s\n", line, src[offs:i+5])
t.Errorf("dst:%d: %s\n", line, dst[offs:])
t.Errorf("src:%d: %s\n", line, src[offs:])
return
}
if s == '\n' {
Expand Down
7 changes: 6 additions & 1 deletion printer/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,12 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int) {
case *ast.SliceLit:
p.print(token.LBRACK)
p.exprList(x.Lbrack, x.Elts, depth+1, commaTerm, x.Rbrack, x.Incomplete)
p.print(token.RBRACK)
mode := noExtraLinebreak
if len(x.Elts) > 0 {
mode |= noExtraBlank
}
p.print(mode, x.Rbrack, token.RBRACK, mode)

case *ast.ComprehensionExpr:
switch x.Tok {
case token.LBRACK: // [...]
Expand Down

0 comments on commit ccdad99

Please sign in to comment.