diff --git a/cl/expr.go b/cl/expr.go index 15356c2ef..53f849aeb 100644 --- a/cl/expr.go +++ b/cl/expr.go @@ -202,7 +202,7 @@ func compileExprLHS(ctx *blockCtx, expr ast.Expr) { case *ast.StarExpr: compileStarExprLHS(ctx, v) default: - log.Panicln("compileExpr failed: unknown -", reflect.TypeOf(v)) + ctx.handleErrorf(v.Pos(), "compileExprLHS unexpected: %T", v) } if rec := ctx.recorder(); rec != nil { rec.recordExpr(ctx, expr, true) @@ -275,12 +275,8 @@ func compileExpr(ctx *blockCtx, expr ast.Expr, inFlags ...int) { compileErrWrapExpr(ctx, v, 0) case *ast.FuncType: ctx.cb.Typ(toFuncType(ctx, v, nil, nil), v) - case *ast.Ellipsis: - panic("compileEllipsis: ast.Ellipsis unexpected") - case *ast.KeyValueExpr: - panic("compileExpr: ast.KeyValueExpr unexpected") default: - log.Panicln("compileExpr failed: unknown -", reflect.TypeOf(v)) + ctx.handleErrorf(v.Pos(), "compileExpr unexpected: %T", v) } if rec := ctx.recorder(); rec != nil { rec.recordExpr(ctx, expr, false) @@ -1167,7 +1163,7 @@ func compileErrWrapExpr(ctx *blockCtx, v *ast.ErrWrapExpr, inFlags int) { VarRef(err). Val(pkg.Import(errorPkgPath).Ref("NewFrame")). Val(err). - Val(sprintAst(pkg.Fset, v.X)). + Val(sprintAst(ctx, pkg.Fset, v.X)). Val(relFile(ctx.relBaseDir, pos.Filename)). Val(pos.Line). Val(currentFuncName). @@ -1189,13 +1185,12 @@ func compileErrWrapExpr(ctx *blockCtx, v *ast.ErrWrapExpr, inFlags int) { } } -func sprintAst(fset *token.FileSet, x ast.Node) string { +func sprintAst(ctx *blockCtx, fset *token.FileSet, x ast.Node) string { var buf bytes.Buffer err := printer.Fprint(&buf, fset, x) if err != nil { - panic("Unexpected error: " + err.Error()) + ctx.handleErrorf(x.Pos(), "unexpected error: %v", err) } - return buf.String() } diff --git a/cl/func_type_and_var.go b/cl/func_type_and_var.go index ca8a37f1a..6d195d2a4 100644 --- a/cl/func_type_and_var.go +++ b/cl/func_type_and_var.go @@ -21,7 +21,6 @@ import ( "go/types" "log" "math/big" - "reflect" "strconv" "github.com/goplus/gop/ast" @@ -179,9 +178,10 @@ func toType(ctx *blockCtx, typ ast.Expr) (t types.Type) { return toIndexType(ctx, v) case *ast.IndexListExpr: return toIndexListType(ctx, v) + default: + ctx.handleErrorf(v.Pos(), "toType unexpected: %T", v) + return types.Typ[types.Invalid] } - log.Panicln("toType: unknown -", reflect.TypeOf(typ)) - return nil } var ( diff --git a/cl/stmt.go b/cl/stmt.go index 2eeec1811..436fb0eca 100644 --- a/cl/stmt.go +++ b/cl/stmt.go @@ -21,7 +21,6 @@ import ( "go/constant" "log" "path/filepath" - "reflect" goast "go/ast" gotoken "go/token" @@ -158,7 +157,7 @@ func compileStmt(ctx *blockCtx, stmt ast.Stmt) { case *ast.EmptyStmt: // do nothing default: - log.Panicln("TODO - compileStmt failed: unknown -", reflect.TypeOf(v)) + ctx.handleErrorf(v.Pos(), "compileStmt unexpected: %T", v) } ctx.cb.EndStmt() }