@Override
public Void visitIfExpression(IfExpression ifExpr, ErrorCollector errors) throws RuntimeException {
// confirm that all conditions are required boolean values.
int i = 0;
for (IfCondition c : ifExpr.conditions) {
MajorType mt = c.condition.getMajorType();
if (mt.getMode() != DataMode.REQUIRED || mt.getMinorType() != MinorType.BIT){
errors.addGeneralError(c.condition.getPosition(),String.format(
"Failure composing If Expression. All conditions must return a required value and be of type boolean. Condition %d was DatMode %s and Type %s.",
i, mt.getMode(), mt.getMinorType()));
}
i++;
}
// confirm that all outcomes are the same type.
final MajorType mt = ifExpr.elseExpression.getMajorType();
i = 0;
for (IfCondition c : ifExpr.conditions) {
MajorType innerT = c.expression.getMajorType();
if (
(innerT.getMode() == DataMode.REPEATED && mt.getMode() != DataMode.REPEATED) || //
(innerT.getMinorType() != mt.getMinorType())
) {
errors.addGeneralError(c.condition.getPosition(),String.format(
"Failure composing If Expression. All expressions must return the same MajorType as the else expression. The %d if condition returned type type %s but the else expression was of type %s",
i, innerT, mt));
}