Skip to content

Commit

Permalink
single argument panic
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rsc committed Mar 30, 2010
1 parent 5d0ec6c commit 00f9f0c
Show file tree
Hide file tree
Showing 60 changed files with 946 additions and 830 deletions.
2 changes: 2 additions & 0 deletions doc/progs/run
Expand Up @@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

set -e

GOBIN="${GOBIN:-$HOME/bin}"

. "$GOROOT"/src/Make.$GOARCH
Expand Down
20 changes: 10 additions & 10 deletions doc/progs/sortmain.go
Expand Up @@ -14,7 +14,7 @@ func ints() {
a := sort.IntArray(data)
sort.Sort(a)
if !sort.IsSorted(a) {
panic()
panic("fail")
}
}

Expand All @@ -23,7 +23,7 @@ func strings() {
a := sort.StringArray(data)
sort.Sort(a)
if !sort.IsSorted(a) {
panic()
panic("fail")
}
}

Expand All @@ -42,18 +42,18 @@ func (p *dayArray) Less(i, j int) bool { return p.data[i].num < p.data[j].num }
func (p *dayArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p.data[i] }

func days() {
Sunday := day{ 0, "SUN", "Sunday" }
Monday := day{ 1, "MON", "Monday" }
Tuesday := day{ 2, "TUE", "Tuesday" }
Wednesday := day{ 3, "WED", "Wednesday" }
Thursday := day{ 4, "THU", "Thursday" }
Friday := day{ 5, "FRI", "Friday" }
Saturday := day{ 6, "SAT", "Saturday" }
Sunday := day{0, "SUN", "Sunday"}
Monday := day{1, "MON", "Monday"}
Tuesday := day{2, "TUE", "Tuesday"}
Wednesday := day{3, "WED", "Wednesday"}
Thursday := day{4, "THU", "Thursday"}
Friday := day{5, "FRI", "Friday"}
Saturday := day{6, "SAT", "Saturday"}
data := []*day{&Tuesday, &Thursday, &Wednesday, &Sunday, &Monday, &Friday, &Saturday}
a := dayArray{data}
sort.Sort(&a)
if !sort.IsSorted(&a) {
panic()
panic("fail")
}
for _, d := range data {
fmt.Printf("%s ", d.longName)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/cgo/ast.go
Expand Up @@ -157,7 +157,7 @@ func walk(x interface{}, p *Prog, context string) {
// everything else just recurs
default:
error(noPos, "unexpected type %T in walk", x)
panic()
panic("unexpected type")

case nil:

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/godoc/index.go
Expand Up @@ -119,7 +119,7 @@ func init() {
// sanity check: if nKinds is too large, the SpotInfo
// accessor functions may need to be updated
if nKinds > 8 {
panic()
panic("nKinds > 8")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/goinstall/download.go
Expand Up @@ -55,7 +55,7 @@ func download(pkg string) (string, os.Error) {
v = &svn
default:
// regexp only allows hg, svn to get through
panic("missing case in download: ", pkg)
panic("missing case in download: " + pkg)
}
if err := vcsCheckout(v, root+m[1], "http://"+m[1], m[1]); err != nil {
return "", err
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/bufio/bufio.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion src/pkg/bytes/bytes_test.go
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/crypto/block/cmac.go
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/exp/eval/eval_test.go
Expand Up @@ -196,7 +196,7 @@ func toValue(val interface{}) Value {
return &funcV{val}
}
log.Crashf("toValue(%T) not implemented", val)
panic()
panic("unreachable")
}

/*
Expand Down
6 changes: 3 additions & 3 deletions src/pkg/exp/eval/expr.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
62 changes: 29 additions & 33 deletions src/pkg/exp/eval/expr1.go
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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")
}

/*
Expand Down Expand Up @@ -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()
Expand All @@ -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)
}
Expand All @@ -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))
Expand Down Expand Up @@ -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")
}
8 changes: 4 additions & 4 deletions src/pkg/exp/eval/gen.go
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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");
}
/*
Expand Down Expand Up @@ -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");
}
`

Expand Down
10 changes: 5 additions & 5 deletions src/pkg/exp/eval/type.go
Expand Up @@ -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) }
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand All @@ -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 {
Expand All @@ -425,7 +425,7 @@ func (t *floatType) maxVal() *bignum.Rational {
return maxFloat64Val
}
log.Crashf("unexpected floating point bit count: %d", bits)
panic()
panic("unreachable")
}

/*
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/exp/ogle/rvalue.go
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/exp/ogle/vars.go
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/go/ast/walk.go
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/pkg/go/parser/parser.go
Expand Up @@ -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")
}


Expand Down

0 comments on commit 00f9f0c

Please sign in to comment.