mirror of
https://github.com/golang/go
synced 2024-11-02 08:01:26 +00:00
cmd/compile: fix println()
println with no arguments accidentally doesn't print a newline. Introduced at CL 55097 Fixes #21808 Change-Id: I9fc7b4271b9b31e4c9b6078f055195dc3907b62c Reviewed-on: https://go-review.googlesource.com/62390 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
87dae58662
commit
02deb77f6d
3 changed files with 24 additions and 4 deletions
|
@ -2071,12 +2071,12 @@ func walkprint(nn *Node, init *Nodes) *Node {
|
||||||
s := nn.List.Slice()
|
s := nn.List.Slice()
|
||||||
t := make([]*Node, 0, len(s)*2)
|
t := make([]*Node, 0, len(s)*2)
|
||||||
for i, n := range s {
|
for i, n := range s {
|
||||||
x := " "
|
t = append(t, n)
|
||||||
if len(s)-1 == i {
|
if i != len(s)-1 {
|
||||||
x = "\n"
|
t = append(t, nodstr(" "))
|
||||||
}
|
}
|
||||||
t = append(t, n, nodstr(x))
|
|
||||||
}
|
}
|
||||||
|
t = append(t, nodstr("\n"))
|
||||||
nn.List.Set(t)
|
nn.List.Set(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
test/fixedbugs/issue21808.go
Normal file
17
test/fixedbugs/issue21808.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// run
|
||||||
|
|
||||||
|
// Copyright 2017 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Make sure println() prints a blank line.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("A")
|
||||||
|
println()
|
||||||
|
fmt.Println("B")
|
||||||
|
}
|
3
test/fixedbugs/issue21808.out
Normal file
3
test/fixedbugs/issue21808.out
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
A
|
||||||
|
|
||||||
|
B
|
Loading…
Reference in a new issue