From 0946e860f1c848b3b50f461b746bbbbbe9abcb9f Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 15 Aug 2023 15:32:48 -0400 Subject: [PATCH] lang: unification: Catch possible rare bug When adding some likely incorrect invariants (while testing code) we hit this panic. While it should not occur, it's probably better to catch it. --- lang/unification/unification.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lang/unification/unification.go b/lang/unification/unification.go index 29d3ff51..af60d33a 100644 --- a/lang/unification/unification.go +++ b/lang/unification/unification.go @@ -133,6 +133,10 @@ func (obj *Unifier) Unify() error { // solver has found a solution, apply it... // we're modifying the AST, so code can't error now... for _, x := range solved.Solutions { + if x.Expr == nil { + // programming error ? + return fmt.Errorf("unexpected invalid solution at: %p", x) + } if obj.Debug { obj.Logf("solution: %p => %+v\t(%+v)", x.Expr, x.Type, x.Expr.String()) }