From 2214954c5189bea0598cf696006d246cae7b3cb4 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 29 Aug 2023 19:15:59 -0400 Subject: [PATCH] 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. --- lang/unification/unification.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lang/unification/unification.go b/lang/unification/unification.go index af60d33a..befd10c7 100644 --- a/lang/unification/unification.go +++ b/lang/unification/unification.go @@ -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