aboutsummaryrefslogtreecommitdiff
path: root/src/pkg
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-03-30 10:34:57 -0700
committerRuss Cox <rsc@golang.org>2010-03-30 10:34:57 -0700
commit00f9f0c0560ce35b9d006eacbeeacf897d19a2bf (patch)
treed56b07c89674ed7162eb30f924600574d0cf464b /src/pkg
parent5d0ec6c076978846f7cbbf4bd2c0dc55d946b0f9 (diff)
downloadgo-00f9f0c0560ce35b9d006eacbeeacf897d19a2bf.tar.xz
single argument panic
note that sortmain.go has been run through hg gofmt; only the formatting of the day initializers changed. i'm happy to revert that formatting if you'd prefer. stop on error in doc/progs/run R=r CC=golang-dev https://golang.org/cl/850041
Diffstat (limited to 'src/pkg')
-rw-r--r--src/pkg/bufio/bufio.go4
-rw-r--r--src/pkg/bytes/bytes_test.go3
-rw-r--r--src/pkg/crypto/block/cmac.go2
-rw-r--r--src/pkg/exp/eval/eval_test.go2
-rw-r--r--src/pkg/exp/eval/expr.go6
-rw-r--r--src/pkg/exp/eval/expr1.go62
-rw-r--r--src/pkg/exp/eval/gen.go8
-rw-r--r--src/pkg/exp/eval/type.go10
-rw-r--r--src/pkg/exp/ogle/rvalue.go4
-rw-r--r--src/pkg/exp/ogle/vars.go2
-rw-r--r--src/pkg/go/ast/walk.go2
-rw-r--r--src/pkg/go/parser/parser.go3
-rw-r--r--src/pkg/go/printer/printer.go4
-rw-r--r--src/pkg/gob/decode.go6
-rw-r--r--src/pkg/http/lex.go8
-rw-r--r--src/pkg/net/fd.go8
-rw-r--r--src/pkg/net/unixsock.go2
-rw-r--r--src/pkg/reflect/value.go4
-rw-r--r--src/pkg/strconv/ftoa_test.go3
-rw-r--r--src/pkg/template/template.go4
-rw-r--r--src/pkg/time/time.go4
-rw-r--r--src/pkg/websocket/server.go4
22 files changed, 72 insertions, 83 deletions
diff --git a/src/pkg/bufio/bufio.go b/src/pkg/bufio/bufio.go
index 9b52a363a3..1af9545dc5 100644
--- a/src/pkg/bufio/bufio.go
+++ b/src/pkg/bufio/bufio.go
@@ -75,7 +75,7 @@ func NewReader(rd io.Reader) *Reader {
b, err := NewReaderSize(rd, defaultBufSize)
if err != nil {
// cannot happen - defaultBufSize is a valid size
- panic("bufio: NewReader: ", err.String())
+ panic(err)
}
return b
}
@@ -353,7 +353,7 @@ func NewWriter(wr io.Writer) *Writer {
b, err := NewWriterSize(wr, defaultBufSize)
if err != nil {
// cannot happen - defaultBufSize is valid size
- panic("bufio: NewWriter: ", err.String())
+ panic(err)
}
return b
}
diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go
index efec1eb8b9..df55ce3ccd 100644
--- a/src/pkg/bytes/bytes_test.go
+++ b/src/pkg/bytes/bytes_test.go
@@ -188,7 +188,8 @@ func bmIndex(b *testing.B, index func([]byte, byte) int, n int) {
for i := 0; i < b.N; i++ {
j := index(buf, 'x')
if j != n-1 {
- panic("bad index", j)
+ println("bad index", j)
+ panic("bad index")
}
}
buf[n-1] = '0'
diff --git a/src/pkg/crypto/block/cmac.go b/src/pkg/crypto/block/cmac.go
index a2f80fe4b3..6082299ab5 100644
--- a/src/pkg/crypto/block/cmac.go
+++ b/src/pkg/crypto/block/cmac.go
@@ -37,7 +37,7 @@ func NewCMAC(c Cipher) hash.Hash {
case 128 / 8:
r = r128
default:
- panic("crypto/block: NewCMAC: invalid cipher block size", n)
+ panic("crypto/block: NewCMAC: invalid cipher block size")
}
d := new(cmac)
diff --git a/src/pkg/exp/eval/eval_test.go b/src/pkg/exp/eval/eval_test.go
index 911c7e4a52..837c4fabdc 100644
--- a/src/pkg/exp/eval/eval_test.go
+++ b/src/pkg/exp/eval/eval_test.go
@@ -196,7 +196,7 @@ func toValue(val interface{}) Value {
return &funcV{val}
}
log.Crashf("toValue(%T) not implemented", val)
- panic()
+ panic("unreachable")
}
/*
diff --git a/src/pkg/exp/eval/expr.go b/src/pkg/exp/eval/expr.go
index 5547aee319..e630578bdd 100644
--- a/src/pkg/exp/eval/expr.go
+++ b/src/pkg/exp/eval/expr.go
@@ -642,7 +642,7 @@ func (a *exprCompiler) compile(x ast.Expr, callCtx bool) *expr {
return ei.compileUnaryExpr(x.Op, v)
}
log.Crashf("unexpected ast node type %T", x)
- panic()
+ panic("unreachable")
typeexpr:
if !callCtx {
@@ -704,7 +704,7 @@ func (a *exprInfo) compileIdent(b *block, constant bool, callCtx bool, name stri
return nil
}
log.Crashf("name %s has unknown type %T", name, def)
- panic()
+ panic("unreachable")
}
func (a *exprInfo) compileVariable(level int, v *Variable) *expr {
@@ -1424,7 +1424,7 @@ func (a *exprInfo) compileBuiltinCallExpr(b *block, ft *FuncType, as []*expr) *e
}
log.Crashf("unexpected built-in function '%s'", ft.builtin)
- panic()
+ panic("unreachable")
}
func (a *exprInfo) compileStarExpr(v *expr) *expr {
diff --git a/src/pkg/exp/eval/expr1.go b/src/pkg/exp/eval/expr1.go
index 28da8eea1b..0e83053f46 100644
--- a/src/pkg/exp/eval/expr1.go
+++ b/src/pkg/exp/eval/expr1.go
@@ -12,9 +12,15 @@ import (
* "As" functions. These retrieve evaluator functions from an
* expr, panicking if the requested evaluator has the wrong type.
*/
-func (a *expr) asBool() func(*Thread) bool { return a.eval.(func(*Thread) bool) }
-func (a *expr) asUint() func(*Thread) uint64 { return a.eval.(func(*Thread) uint64) }
-func (a *expr) asInt() func(*Thread) int64 { return a.eval.(func(*Thread) int64) }
+func (a *expr) asBool() func(*Thread) bool {
+ return a.eval.(func(*Thread) bool)
+}
+func (a *expr) asUint() func(*Thread) uint64 {
+ return a.eval.(func(*Thread) uint64)
+}
+func (a *expr) asInt() func(*Thread) int64 {
+ return a.eval.(func(*Thread) int64)
+}
func (a *expr) asIdealInt() func() *bignum.Integer {
return a.eval.(func() *bignum.Integer)
}
@@ -33,10 +39,18 @@ func (a *expr) asArray() func(*Thread) ArrayValue {
func (a *expr) asStruct() func(*Thread) StructValue {
return a.eval.(func(*Thread) StructValue)
}
-func (a *expr) asPtr() func(*Thread) Value { return a.eval.(func(*Thread) Value) }
-func (a *expr) asFunc() func(*Thread) Func { return a.eval.(func(*Thread) Func) }
-func (a *expr) asSlice() func(*Thread) Slice { return a.eval.(func(*Thread) Slice) }
-func (a *expr) asMap() func(*Thread) Map { return a.eval.(func(*Thread) Map) }
+func (a *expr) asPtr() func(*Thread) Value {
+ return a.eval.(func(*Thread) Value)
+}
+func (a *expr) asFunc() func(*Thread) Func {
+ return a.eval.(func(*Thread) Func)
+}
+func (a *expr) asSlice() func(*Thread) Slice {
+ return a.eval.(func(*Thread) Slice)
+}
+func (a *expr) asMap() func(*Thread) Map {
+ return a.eval.(func(*Thread) Map)
+}
func (a *expr) asMulti() func(*Thread) []Value {
return a.eval.(func(*Thread) []Value)
}
@@ -72,7 +86,7 @@ func (a *expr) asInterface() func(*Thread) interface{} {
default:
log.Crashf("unexpected expression node type %T at %v", a.eval, a.pos)
}
- panic()
+ panic("fail")
}
/*
@@ -210,26 +224,17 @@ func (a *expr) genUnaryOpNeg(v *expr) {
switch a.t.lit().(type) {
case *uintType:
vf := v.asUint()
- a.eval = func(t *Thread) uint64 {
- v := vf(t)
- return -v
- }
+ a.eval = func(t *Thread) uint64 { v := vf(t); return -v }
case *intType:
vf := v.asInt()
- a.eval = func(t *Thread) int64 {
- v := vf(t)
- return -v
- }
+ a.eval = func(t *Thread) int64 { v := vf(t); return -v }
case *idealIntType:
v := v.asIdealInt()()
val := v.Neg()
a.eval = func() *bignum.Integer { return val }
case *floatType:
vf := v.asFloat()
- a.eval = func(t *Thread) float64 {
- v := vf(t)
- return -v
- }
+ a.eval = func(t *Thread) float64 { v := vf(t); return -v }
case *idealFloatType:
v := v.asIdealFloat()()
val := v.Neg()
@@ -243,10 +248,7 @@ func (a *expr) genUnaryOpNot(v *expr) {
switch a.t.lit().(type) {
case *boolType:
vf := v.asBool()
- a.eval = func(t *Thread) bool {
- v := vf(t)
- return !v
- }
+ a.eval = func(t *Thread) bool { v := vf(t); return !v }
default:
log.Crashf("unexpected type %v at %v", a.t, a.pos)
}
@@ -256,16 +258,10 @@ func (a *expr) genUnaryOpXor(v *expr) {
switch a.t.lit().(type) {
case *uintType:
vf := v.asUint()
- a.eval = func(t *Thread) uint64 {
- v := vf(t)
- return ^v
- }
+ a.eval = func(t *Thread) uint64 { v := vf(t); return ^v }
case *intType:
vf := v.asInt()
- a.eval = func(t *Thread) int64 {
- v := vf(t)
- return ^v
- }
+ a.eval = func(t *Thread) int64 { v := vf(t); return ^v }
case *idealIntType:
v := v.asIdealInt()()
val := v.Neg().Sub(bignum.Int(1))
@@ -1905,5 +1901,5 @@ func genAssign(lt Type, r *expr) func(lv Value, t *Thread) {
default:
log.Crashf("unexpected left operand type %v at %v", lt, r.pos)
}
- panic()
+ panic("fail")
}
diff --git a/src/pkg/exp/eval/gen.go b/src/pkg/exp/eval/gen.go
index ea421ff9c4..969d655862 100644
--- a/src/pkg/exp/eval/gen.go
+++ b/src/pkg/exp/eval/gen.go
@@ -103,12 +103,12 @@ var binOps = []Op{
Op{Name: "Sub", Expr: "l - r", ConstExpr: "l.Sub(r)", Types: numbers},
Op{Name: "Mul", Expr: "l * r", ConstExpr: "l.Mul(r)", Types: numbers},
Op{Name: "Quo",
- Body: "if r == 0 { t.Abort(DivByZeroError{}) } ret = l / r",
+ Body: "if r == 0 { t.Abort(DivByZeroError{}) }; ret = l / r",
ConstExpr: "l.Quo(r)",
Types: numbers,
},
Op{Name: "Rem",
- Body: "if r == 0 { t.Abort(DivByZeroError{}) } ret = l % r",
+ Body: "if r == 0 { t.Abort(DivByZeroError{}) }; ret = l % r",
ConstExpr: "l.Rem(r)",
Types: integers,
},
@@ -186,7 +186,7 @@ func (a *expr) asInterface() (func(*Thread) interface{}) {
default:
log.Crashf("unexpected expression node type %T at %v", a.eval, a.pos);
}
- panic();
+ panic("fail");
}
/*
@@ -357,7 +357,7 @@ func genAssign(lt Type, r *expr) (func(lv Value, t *Thread)) {
default:
log.Crashf("unexpected left operand type %v at %v", lt, r.pos);
}
- panic();
+ panic("fail");
}
`
diff --git a/src/pkg/exp/eval/type.go b/src/pkg/exp/eval/type.go
index 2b2a632cd0..fbb428679e 100644
--- a/src/pkg/exp/eval/type.go
+++ b/src/pkg/exp/eval/type.go
@@ -231,7 +231,7 @@ func (t *uintType) Zero() Value {
res := uint64V(0)
return &res
}
- panic("unexpected uint bit count: ", t.Bits)
+ panic("unexpected uint bit count")
}
func (t *uintType) minVal() *bignum.Rational { return bignum.Rat(0, 1) }
@@ -304,7 +304,7 @@ func (t *intType) Zero() Value {
res := intV(0)
return &res
}
- panic("unexpected int bit count: ", t.Bits)
+ panic("unexpected int bit count")
}
func (t *intType) minVal() *bignum.Rational {
@@ -390,7 +390,7 @@ func (t *floatType) Zero() Value {
res := floatV(0)
return &res
}
- panic("unexpected float bit count: ", t.Bits)
+ panic("unexpected float bit count")
}
var maxFloat32Val = bignum.MakeRat(bignum.Int(0xffffff).Shl(127-23), bignum.Nat(1))
@@ -410,7 +410,7 @@ func (t *floatType) minVal() *bignum.Rational {
return minFloat64Val
}
log.Crashf("unexpected floating point bit count: %d", bits)
- panic()
+ panic("unreachable")
}
func (t *floatType) maxVal() *bignum.Rational {
@@ -425,7 +425,7 @@ func (t *floatType) maxVal() *bignum.Rational {
return maxFloat64Val
}
log.Crashf("unexpected floating point bit count: %d", bits)
- panic()
+ panic("unreachable")
}
/*
diff --git a/src/pkg/exp/ogle/rvalue.go b/src/pkg/exp/ogle/rvalue.go
index ba915ed5cb..3d630f9366 100644
--- a/src/pkg/exp/ogle/rvalue.go
+++ b/src/pkg/exp/ogle/rvalue.go
@@ -232,7 +232,7 @@ func (v remoteFloat) aGet(a aborter) float64 {
case 8:
return v.r.p.ToFloat64(bits)
}
- panic("Unexpected float size ", v.size)
+ panic("Unexpected float size")
}
func (v remoteFloat) Set(t *eval.Thread, x float64) {
@@ -247,7 +247,7 @@ func (v remoteFloat) aSet(a aborter, x float64) {
case 8:
bits = v.r.p.FromFloat64(x)
default:
- panic("Unexpected float size ", v.size)
+ panic("Unexpected float size")
}
v.r.Set(a, v.size, bits)
}
diff --git a/src/pkg/exp/ogle/vars.go b/src/pkg/exp/ogle/vars.go
index e6298bc481..eed60acec5 100644
--- a/src/pkg/exp/ogle/vars.go
+++ b/src/pkg/exp/ogle/vars.go
@@ -63,7 +63,7 @@ func (v remoteFramePtr) Get(t *eval.Thread) eval.Value {
}
t.Abort(NotOnStack{v.fn, g})
- panic()
+ panic("fail")
}
func (v remoteFramePtr) Set(t *eval.Thread, x eval.Value) {
diff --git a/src/pkg/go/ast/walk.go b/src/pkg/go/ast/walk.go
index 2137ddaa46..6c9837a01d 100644
--- a/src/pkg/go/ast/walk.go
+++ b/src/pkg/go/ast/walk.go
@@ -316,7 +316,7 @@ func Walk(v Visitor, node interface{}) {
default:
fmt.Printf("ast.Walk: unexpected type %T", n)
- panic()
+ panic("ast.Walk")
}
v.Visit(nil)
diff --git a/src/pkg/go/parser/parser.go b/src/pkg/go/parser/parser.go
index 2002d3818b..6831a53de2 100644
--- a/src/pkg/go/parser/parser.go
+++ b/src/pkg/go/parser/parser.go
@@ -1738,8 +1738,7 @@ func (p *parser) parseForStmt() ast.Stmt {
return &ast.ForStmt{pos, s1, p.makeExpr(s2), s3, body}
}
- panic() // unreachable
- return nil
+ panic("unreachable")
}
diff --git a/src/pkg/go/printer/printer.go b/src/pkg/go/printer/printer.go
index 5a12c6edb5..2316a459bb 100644
--- a/src/pkg/go/printer/printer.go
+++ b/src/pkg/go/printer/printer.go
@@ -107,7 +107,7 @@ func (p *printer) internalError(msg ...interface{}) {
if debug {
fmt.Print(p.pos.String() + ": ")
fmt.Println(msg)
- panic()
+ panic("go/printer")
}
}
@@ -791,7 +791,7 @@ func (p *printer) print(args ...interface{}) {
}
default:
fmt.Fprintf(os.Stderr, "print: unsupported argument type %T\n", f)
- panic()
+ panic("go/printer type")
}
p.pos = next
diff --git a/src/pkg/gob/decode.go b/src/pkg/gob/decode.go
index 9dea080f8f..3b14841afd 100644
--- a/src/pkg/gob/decode.go
+++ b/src/pkg/gob/decode.go
@@ -777,7 +777,7 @@ func init() {
case unsafe.Sizeof(float64(0)):
op = decFloat64
default:
- panic("gob: unknown size of float", unsafe.Sizeof(float(0)))
+ panic("gob: unknown size of float")
}
decOpMap[valueKind(float(0))] = op
@@ -791,7 +791,7 @@ func init() {
op = decInt64
uop = decUint64
default:
- panic("gob: unknown size of int/uint", unsafe.Sizeof(int(0)))
+ panic("gob: unknown size of int/uint")
}
decOpMap[valueKind(int(0))] = op
decOpMap[valueKind(uint(0))] = uop
@@ -803,7 +803,7 @@ func init() {
case unsafe.Sizeof(uint64(0)):
uop = decUint64
default:
- panic("gob: unknown size of uintptr", unsafe.Sizeof(uintptr(0)))
+ panic("gob: unknown size of uintptr")
}
decOpMap[valueKind(uintptr(0))] = uop
}
diff --git a/src/pkg/http/lex.go b/src/pkg/http/lex.go
index d25c4e4038..93b67e7017 100644
--- a/src/pkg/http/lex.go
+++ b/src/pkg/http/lex.go
@@ -10,20 +10,16 @@ func isSeparator(c byte) bool {
switch c {
case '(', ')', '<', '>', '@', ',', ';', ':', '\\', '"', '/', '[', ']', '?', '=', '{', '}', ' ', '\t':
return true
- default:
- return false
}
- panic()
+ return false
}
func isSpace(c byte) bool {
switch c {
case ' ', '\t', '\r', '\n':
return true
- default:
- return false
}
- panic()
+ return false
}
func isCtl(c byte) bool { return (0 <= c && c <= 31) || c == 127 }
diff --git a/src/pkg/net/fd.go b/src/pkg/net/fd.go
index 5619b9ec58..28e85be2a3 100644
--- a/src/pkg/net/fd.go
+++ b/src/pkg/net/fd.go
@@ -11,6 +11,7 @@ import (
"os"
"sync"
"syscall"
+ "time"
)
// Network file descriptor.
@@ -176,12 +177,7 @@ func (s *pollServer) WakeFD(fd *netFD, mode int) {
}
func (s *pollServer) Now() int64 {
- sec, nsec, err := os.Time()
- if err != nil {
- panic("net: os.Time: ", err.String())
- }
- nsec += sec * 1e9
- return nsec
+ return time.Nanoseconds()
}
func (s *pollServer) CheckDeadlines() {
diff --git a/src/pkg/net/unixsock.go b/src/pkg/net/unixsock.go
index 727b99f7af..daf71c0066 100644
--- a/src/pkg/net/unixsock.go
+++ b/src/pkg/net/unixsock.go
@@ -25,7 +25,7 @@ func unixSocket(net string, laddr, raddr *UnixAddr, mode string) (fd *netFD, err
var la, ra syscall.Sockaddr
switch mode {
default:
- panic("unixSocket", mode)
+ panic("unixSocket mode " + mode)
case "dial":
if laddr != nil {
diff --git a/src/pkg/reflect/value.go b/src/pkg/reflect/value.go
index be786e91a3..f21c564d53 100644
--- a/src/pkg/reflect/value.go
+++ b/src/pkg/reflect/value.go
@@ -571,7 +571,7 @@ func (v *ArrayValue) Elem(i int) Value {
typ := v.typ.(*ArrayType).Elem()
n := v.Len()
if i < 0 || i >= n {
- panic("index", i, "in array len", n)
+ panic("array index out of bounds")
}
p := addr(uintptr(v.addr()) + uintptr(i)*typ.Size())
return newValue(typ, p, v.canSet)
@@ -642,7 +642,7 @@ func (v *SliceValue) Get() uintptr {
func (v *SliceValue) Slice(beg, end int) *SliceValue {
cap := v.Cap()
if beg < 0 || end < beg || end > cap {
- panic("slice bounds [", beg, ":", end, "] with capacity ", cap)
+ panic("slice index out of bounds")
}
typ := v.typ.(*SliceType)
s := new(SliceHeader)
diff --git a/src/pkg/strconv/ftoa_test.go b/src/pkg/strconv/ftoa_test.go
index 70497bf82a..3771c40b91 100644
--- a/src/pkg/strconv/ftoa_test.go
+++ b/src/pkg/strconv/ftoa_test.go
@@ -101,7 +101,8 @@ var ftoatests = []ftoaTest{
func TestFtoa(t *testing.T) {
if FloatSize != 32 {
- panic("floatsize: ", FloatSize)
+ println("floatsize: ", FloatSize)
+ panic("floatsize")
}
for i := 0; i < len(ftoatests); i++ {
test := &ftoatests[i]
diff --git a/src/pkg/template/template.go b/src/pkg/template/template.go
index e2f70c1a53..54c22ba8df 100644
--- a/src/pkg/template/template.go
+++ b/src/pkg/template/template.go
@@ -983,7 +983,7 @@ func ParseFile(filename string, fmap FormatterMap) (t *Template, err os.Error) {
func MustParse(s string, fmap FormatterMap) *Template {
t, err := Parse(s, fmap)
if err != nil {
- panic("template parse error: ", err.String())
+ panic("template.MustParse error: " + err.String())
}
return t
}
@@ -993,7 +993,7 @@ func MustParse(s string, fmap FormatterMap) *Template {
func MustParseFile(filename string, fmap FormatterMap) *Template {
b, err := ioutil.ReadFile(filename)
if err != nil {
- panic("template parse error: ", err.String())
+ panic("template.MustParseFile error: " + err.String())
}
return MustParse(string(b), fmap)
}
diff --git a/src/pkg/time/time.go b/src/pkg/time/time.go
index d84807e836..7b78874852 100644
--- a/src/pkg/time/time.go
+++ b/src/pkg/time/time.go
@@ -15,7 +15,7 @@ import (
func Seconds() int64 {
sec, _, err := os.Time()
if err != nil {
- panic("time: os.Time: ", err.String())
+ panic(err)
}
return sec
}
@@ -25,7 +25,7 @@ func Seconds() int64 {
func Nanoseconds() int64 {
sec, nsec, err := os.Time()
if err != nil {
- panic("time: os.Time: ", err.String())
+ panic(err)
}
return sec*1e9 + nsec
}
diff --git a/src/pkg/websocket/server.go b/src/pkg/websocket/server.go
index 78c42990a0..cc1ff93854 100644
--- a/src/pkg/websocket/server.go
+++ b/src/pkg/websocket/server.go
@@ -62,7 +62,7 @@ func getKeyNumber(s string) (r uint32) {
func (f Handler) ServeHTTP(c *http.Conn, req *http.Request) {
rwc, buf, err := c.Hijack()
if err != nil {
- panic("Hijack failed: ", err.String())
+ panic("Hijack failed: " + err.String())
return
}
// The server should abort the WebSocket connection if it finds
@@ -200,7 +200,7 @@ func (f Draft75Handler) ServeHTTP(c *http.Conn, req *http.Request) {
rwc, buf, err := c.Hijack()
if err != nil {
- panic("Hijack failed: ", err.String())
+ panic("Hijack failed: " + err.String())
return
}
defer rwc.Close()