1
0
mirror of https://github.com/golang/go synced 2024-11-22 01:34:41 -07:00

exp/template: make -0 be an unsigned int.

Fix (inconsequential) type error in list initializer.

R=rsc
CC=golang-dev
https://golang.org/cl/4638058
This commit is contained in:
Rob Pike 2011-06-23 10:19:29 +10:00
parent d7df79a7e5
commit 96731619ce
2 changed files with 10 additions and 5 deletions

View File

@ -68,6 +68,7 @@ const (
nodeEnd
nodeField
nodeIdentifier
nodeList
nodeNumber
nodeRange
nodeString
@ -82,7 +83,7 @@ type listNode struct {
}
func newList() *listNode {
return &listNode{nodeType: nodeText}
return &listNode{nodeType: nodeList}
}
func (l *listNode) append(n node) {
@ -178,8 +179,7 @@ func (f *fieldNode) String() string {
}
// numberNode holds a number, signed or unsigned, integer, floating, or imaginary.
// The value is parsed and stored under all the types that can represent the value
// (although for simplicity -0 is not considered a valid unsigned integer).
// The value is parsed and stored under all the types that can represent the value.
// This simulates in a small amount of code the behavior of Go's ideal constants.
// TODO: booleans, complex numbers.
type numberNode struct {
@ -207,7 +207,7 @@ func newNumber(text string) (*numberNode, os.Error) {
}
}
// Do integer test first so we get 0x123 etc.
u, err := strconv.Btoui64(text, 0) // will fail for -0; tough.
u, err := strconv.Btoui64(text, 0) // will fail for -0; fixed below.
if err == nil {
n.isUint = true
n.uint64 = u
@ -216,6 +216,10 @@ func newNumber(text string) (*numberNode, os.Error) {
if err == nil {
n.isInt = true
n.int64 = i
if i == 0 {
n.isUint = true // in case of -0.
n.uint64 = u
}
}
// If an integer extraction succeeded, promote the float.
if n.isInt {

View File

@ -25,6 +25,7 @@ type numberTest struct {
var numberTests = []numberTest{
// basics
{"0", true, true, true, false, 0, 0, 0},
{"-0", true, true, true, false, 0, 0, 0}, // check that -0 is a uint.
{"73", true, true, true, false, 73, 73, 73},
{"-73", true, false, true, false, -73, 0, -73},
{"+73", true, false, true, false, 73, 0, 73},
@ -37,7 +38,7 @@ var numberTests = []numberTest{
{"4i", false, false, true, true, 0, 0, 4},
// funny bases
{"0123", true, true, true, false, 0123, 0123, 0123},
{"-0x0", true, false, true, false, 0, 0, 0},
{"-0x0", true, true, true, false, 0, 0, 0},
{"0xdeadbeef", true, true, true, false, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef},
// some broken syntax
{text: "+-2"},