Skip to content

Commit

Permalink
starlark,resolve,internal/compile: replace log.Fatalf with log.Panicf (
Browse files Browse the repository at this point in the history
…#235)

Replace calls to log.Fatal/log.Fatalf with log.Panicf calls so that we
get a stacktrace.
  • Loading branch information
aarzilli authored and adonovan committed Aug 19, 2019
1 parent 1a17001 commit 688506e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions internal/compile/compile.go
Expand Up @@ -1000,7 +1000,7 @@ func (fcomp *fcomp) set(id *syntax.Ident) {
case resolve.Global:
fcomp.emit1(SETGLOBAL, uint32(bind.Index))
default:
log.Fatalf("%s: set(%s): not global/local/cell (%d)", id.NamePos, id.Name, bind.Scope)
log.Panicf("%s: set(%s): not global/local/cell (%d)", id.NamePos, id.Name, bind.Scope)
}
}

Expand Down Expand Up @@ -1028,7 +1028,7 @@ func (fcomp *fcomp) lookup(id *syntax.Ident) {
case resolve.Universal:
fcomp.emit1(UNIVERSAL, fcomp.pcomp.nameIndex(id.Name))
default:
log.Fatalf("%s: compiler.lookup(%s): scope = %d", id.NamePos, id.Name, bind.Scope)
log.Panicf("%s: compiler.lookup(%s): scope = %d", id.NamePos, id.Name, bind.Scope)
}
}

Expand Down Expand Up @@ -1224,7 +1224,7 @@ func (fcomp *fcomp) stmt(stmt syntax.Stmt) {

default:
start, _ := stmt.Span()
log.Fatalf("%s: exec: unexpected statement %T", start, stmt)
log.Panicf("%s: exec: unexpected statement %T", start, stmt)
}
}

Expand Down Expand Up @@ -1374,7 +1374,7 @@ func (fcomp *fcomp) expr(e syntax.Expr) {
case syntax.TILDE:
fcomp.emit(TILDE)
default:
log.Fatalf("%s: unexpected unary op: %s", e.OpPos, e.Op)
log.Panicf("%s: unexpected unary op: %s", e.OpPos, e.Op)
}

case *syntax.BinaryExpr:
Expand Down Expand Up @@ -1436,7 +1436,7 @@ func (fcomp *fcomp) expr(e syntax.Expr) {

default:
start, _ := e.Span()
log.Fatalf("%s: unexpected expr %T", start, e)
log.Panicf("%s: unexpected expr %T", start, e)
}
}

Expand Down Expand Up @@ -1619,7 +1619,7 @@ func (fcomp *fcomp) binop(pos syntax.Position, op syntax.Token) {
fcomp.emit(Opcode(op-syntax.EQL) + EQL)

default:
log.Fatalf("%s: unexpected binary op: %s", pos, op)
log.Panicf("%s: unexpected binary op: %s", pos, op)
}
}

Expand Down Expand Up @@ -1778,7 +1778,7 @@ func (fcomp *fcomp) comprehension(comp *syntax.Comprehension, clauseIndex int) {
}

start, _ := clause.Span()
log.Fatalf("%s: unexpected comprehension clause %T", start, clause)
log.Panicf("%s: unexpected comprehension clause %T", start, clause)
}

func (fcomp *fcomp) function(f *resolve.Function) {
Expand Down
6 changes: 3 additions & 3 deletions resolve/resolve.go
Expand Up @@ -557,7 +557,7 @@ func (r *resolver) stmt(stmt syntax.Stmt) {
}

default:
log.Fatalf("unexpected stmt %T", stmt)
log.Panicf("unexpected stmt %T", stmt)
}
}

Expand Down Expand Up @@ -782,7 +782,7 @@ func (r *resolver) expr(e syntax.Expr) {
r.expr(e.X)

default:
log.Fatalf("unexpected expr %T", e)
log.Panicf("unexpected expr %T", e)
}
}

Expand Down Expand Up @@ -901,7 +901,7 @@ func lookupLocal(use use) *Binding {
if bind, ok := env.bindings[use.id.Name]; ok {
if bind.Scope == Free {
// shouldn't exist till later
log.Fatalf("%s: internal error: %s, %v", use.id.NamePos, use.id.Name, bind)
log.Panicf("%s: internal error: %s, %v", use.id.NamePos, use.id.Name, bind)
}
return bind // found
}
Expand Down
2 changes: 1 addition & 1 deletion starlark/eval.go
Expand Up @@ -377,7 +377,7 @@ func makeToplevelFunction(prog *compile.Program, predeclared StringDict) *Functi
case float64:
v = Float(c)
default:
log.Fatalf("unexpected constant %T: %v", c, c)
log.Panicf("unexpected constant %T: %v", c, c)
}
constants[i] = v
}
Expand Down

0 comments on commit 688506e

Please sign in to comment.