mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
cmd/compile: fix print/println when input is uint
Fixes #21887 Change-Id: I30e8e03ecfb67a2c4deedc2c8436da4c4782136d Reviewed-on: https://go-review.googlesource.com/63971 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
7246585f8c
commit
4cff104771
@ -2127,13 +2127,13 @@ func walkprint(nn *Node, init *Nodes) *Node {
|
||||
case TSLICE:
|
||||
on = syslook("printslice")
|
||||
on = substArgTypes(on, n.Type) // any-1
|
||||
case TUINT64:
|
||||
case TUINT, TUINT8, TUINT16, TUINT32, TUINT64, TUINTPTR:
|
||||
if isRuntimePkg(n.Type.Sym.Pkg) && n.Type.Sym.Name == "hex" {
|
||||
on = syslook("printhex")
|
||||
} else {
|
||||
on = syslook("printuint")
|
||||
}
|
||||
case TINT, TUINT, TUINTPTR, TINT8, TUINT8, TINT16, TUINT16, TINT32, TUINT32, TINT64:
|
||||
case TINT, TINT8, TINT16, TINT32, TINT64:
|
||||
on = syslook("printint")
|
||||
case TFLOAT32, TFLOAT64:
|
||||
on = syslook("printfloat")
|
||||
|
25
test/fixedbugs/issue21887.go
Normal file
25
test/fixedbugs/issue21887.go
Normal file
@ -0,0 +1,25 @@
|
||||
// cmpout
|
||||
|
||||
// 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.
|
||||
|
||||
// Issue 21887: println(^uint(0)) fails to compile
|
||||
|
||||
package main
|
||||
|
||||
import "strconv"
|
||||
|
||||
func main() {
|
||||
if strconv.IntSize == 32 {
|
||||
println(^uint(0))
|
||||
} else {
|
||||
println(^uint32(0))
|
||||
}
|
||||
|
||||
if strconv.IntSize == 64 {
|
||||
println(^uint(0))
|
||||
} else {
|
||||
println(^uint64(0))
|
||||
}
|
||||
}
|
2
test/fixedbugs/issue21887.out
Normal file
2
test/fixedbugs/issue21887.out
Normal file
@ -0,0 +1,2 @@
|
||||
4294967295
|
||||
18446744073709551615
|
@ -19,6 +19,11 @@ func main() {
|
||||
println(([]int)(nil)) // printslice
|
||||
println(int64(-7)) // printint
|
||||
println(uint64(7)) // printuint
|
||||
println(uint32(7)) // printuint
|
||||
println(uint16(7)) // printuint
|
||||
println(uint8(7)) // printuint
|
||||
println(uint(7)) // printuint
|
||||
println(uintptr(7)) // printuint
|
||||
println(8.0) // printfloat
|
||||
println(complex(9.0, 10.0)) // printcomplex
|
||||
println(true) // printbool
|
||||
@ -28,11 +33,18 @@ func main() {
|
||||
|
||||
// test goprintf
|
||||
defer println((interface{})(nil))
|
||||
defer println((interface{f()})(nil))
|
||||
defer println((interface {
|
||||
f()
|
||||
})(nil))
|
||||
defer println((map[int]int)(nil))
|
||||
defer println(([]int)(nil))
|
||||
defer println(int64(-11))
|
||||
defer println(uint64(12))
|
||||
defer println(uint32(12))
|
||||
defer println(uint16(12))
|
||||
defer println(uint8(12))
|
||||
defer println(uint(12))
|
||||
defer println(uintptr(12))
|
||||
defer println(13.0)
|
||||
defer println(complex(14.0, 15.0))
|
||||
defer println(true)
|
||||
|
@ -4,6 +4,11 @@
|
||||
[0/0]0x0
|
||||
-7
|
||||
7
|
||||
7
|
||||
7
|
||||
7
|
||||
7
|
||||
7
|
||||
+8.000000e+000
|
||||
(+9.000000e+000+1.000000e+001i)
|
||||
true
|
||||
@ -17,6 +22,11 @@ true
|
||||
(+1.400000e+001+1.500000e+001i)
|
||||
+1.300000e+001
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
12
|
||||
-11
|
||||
[0/0]0x0
|
||||
0x0
|
||||
|
Loading…
x
Reference in New Issue
Block a user