lang: unification: Error instead of panic

This is still a programming error, but not as dangerous for the edge
cases we might still have present, particularly with printf.
This commit is contained in:
James Shubin
2023-08-29 19:15:59 -04:00
parent ec515f4fb5
commit 2214954c51

View File

@@ -143,7 +143,12 @@ func (obj *Unifier) Unify() error {
// apply this to each AST node
if err := x.Expr.SetType(x.Type); err != nil {
// programming error!
panic(fmt.Sprintf("error setting type: %+v, error: %+v", x.Expr, err))
// If we error here, it's probably a bug. Likely we
// should have caught something during type unification,
// but it slipped through and the function Build API is
// catching it instead. Try and root cause it to avoid
// leaving any ghosts in the code.
return fmt.Errorf("error setting type: %+v, error: %+v", x.Expr, err)
}
}
return nil