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!
This commit is contained in:
James Shubin
2019-01-20 03:42:36 -05:00
parent 32e29862f2
commit 7a28b00d75

View File

@@ -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
}