Skip to content

Commit

Permalink
Make error checking robust enough for gokv
Browse files Browse the repository at this point in the history
  • Loading branch information
tchajed committed Jul 3, 2024
1 parent 24e04e9 commit 20cad8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 14 additions & 3 deletions goose.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ func (ctx Ctx) makeExpr(args []ast.Expr) coq.CallExpr {
coq.UnitLiteral{})
default:
ctx.unsupported(args[0],
"make of should be slice or map, got %v", ty)
"make type should be slice or map, got %v", ty)
}
return coq.CallExpr{}
}
Expand Down Expand Up @@ -1808,7 +1808,7 @@ func (ctx Ctx) branchStmt(s *ast.BranchStmt) coq.Expr {
// getSpawn returns a non-nil spawned thread if the expression is a go call
func (ctx Ctx) goStmt(e *ast.GoStmt) coq.Expr {
if len(e.Call.Args) > 0 {
ctx.unsupported(e, "go statement with parameters")
ctx.todo(e, "go statement with parameters")
}
return ctx.spawnExpr(e.Call.Fun)
}
Expand Down Expand Up @@ -1867,6 +1867,8 @@ func (ctx Ctx) stmtInBlock(s ast.Stmt, usage ExprValUsage) (coq.Binding, bool) {
ctx.todo(s, "check for switch statement")
case *ast.TypeSwitchStmt:
ctx.todo(s, "check for type switch statement")
case *ast.SelectStmt:
ctx.unsupported(s, "select statement")
default:
ctx.unsupported(s, "statement")
}
Expand Down Expand Up @@ -1941,7 +1943,10 @@ func (ctx Ctx) funcDecl(d *ast.FuncDecl) coq.FuncDecl {
if star, ok := rcvrTy.(*ast.StarExpr); ok {
rcvrTy = star.X
}
ident := rcvrTy.(*ast.Ident)
ident, ok := rcvrTy.(*ast.Ident)
if !ok {
ctx.unsupported(rcvr, "unexpected function receiver type: %s", ctx.printGo(rcvrTy))
}
fd.Name = coq.MethodName(ident.Name, d.Name.Name)
fd.Args = append(fd.Args, ctx.field(rcvr))
}
Expand All @@ -1960,6 +1965,9 @@ func (ctx Ctx) constSpec(spec *ast.ValueSpec) coq.ConstDecl {
AddTypes: ctx.PkgConfig.TypeCheck,
}
addSourceDoc(spec.Comment, &cd.Comment)
if len(spec.Values) == 0 {
ctx.unsupported(spec, "const with no value")
}
val := spec.Values[0]
cd.Val = ctx.expr(val)
if spec.Type == nil {
Expand Down Expand Up @@ -2147,6 +2155,9 @@ func (ctx Ctx) maybeDecls(d ast.Decl) []coq.Decl {
case *ast.FuncDecl:
var cvs []coq.Decl
if !ctx.SkipInterfaces {
if d.Body == nil {
ctx.unsupported(d, "function declaration with no body")
}
for _, stmt := range d.Body.List {
cvs = ctx.stmtInterface(cvs, stmt)
}
Expand Down
4 changes: 4 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func (ctx Ctx) coqTypeOfType(n ast.Node, t types.Type) coq.Type {
return coq.TypeIdent("boolT")
case "string", "untyped string":
return coq.TypeIdent("stringT")
case "int":
ctx.todo(n, "basic type int (use uint64)")
default:
ctx.unsupported(n, "basic type %s", t.Name())
}
Expand Down Expand Up @@ -191,6 +193,8 @@ func (ctx Ctx) coqType(e ast.Expr) coq.Type {
return coq.SliceType{Value: ctx.coqType(e.Elt)}
case *ast.FuncType:
return ctx.coqFuncType(e)
case *ast.IndexExpr:
ctx.todo(e, "unsupported generic type instantiation")
default:
ctx.unsupported(e, "unexpected type expr")
}
Expand Down

0 comments on commit 20cad8d

Please sign in to comment.