Commit 96731619 authored by Rob Pike's avatar Rob Pike

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
parent d7df79a7
......@@ -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 {
......
......@@ -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"},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment