From 7a28b00d750d83c470b1b5ac8ca0f165360c804a Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 20 Jan 2019 03:42:36 -0500 Subject: [PATCH] lang: If expression was missing two invariants I forgot to ensure that the type of the final expression matched the type of each of the branches. It's rare, but possible for this to occur. Luckily, this never would have caused a panic, because the func engine would have caught the issue anyways, but it's still better we catch it here first! --- lang/structs.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lang/structs.go b/lang/structs.go index 3fccc088..a41e8bde 100644 --- a/lang/structs.go +++ b/lang/structs.go @@ -5583,6 +5583,18 @@ func (obj *ExprIf) Unify() ([]interfaces.Invariant, error) { } invariants = append(invariants, branchesInvar) + // the two branches must match the type of the whole expression + thenInvar := &unification.EqualityInvariant{ + Expr1: obj, + Expr2: obj.ThenBranch, + } + invariants = append(invariants, thenInvar) + elseInvar := &unification.EqualityInvariant{ + Expr1: obj, + Expr2: obj.ElseBranch, + } + invariants = append(invariants, elseInvar) + return invariants, nil }