Check-if/when/unless-expression
Check if an if/when/unless-then-else expression
is statically well-formed.
- Signature
(check-if/when/unless-expression test test-negp then else expr ctxt)
→
result
- Arguments
- test — Guard (expressionp test).
- test-negp — Guard (booleanp test-negp).
- then — Guard (expressionp then).
- else — Guard (expressionp else).
- expr — Guard (expressionp expr).
- ctxt — Guard (contextp ctxt).
- Returns
- result — Type (type-resultp result).
We first check the test expression, which must be boolean.
Then we check the two branch expressions, in contexts augmented with
(i) the test and its negation when test-negp is nil or
(ii) the negation of the test and the test otherwise:
this parameter is nil for an if/when-then-else expression,
t for an unless-then-else expression;
that is, the parameter says whether the test should be negated.
We also ensure that the two branches' types are compatible,
namely that they have a supremum type (list),
which is the type (list) of the if-then-else expression.