Do not throw an exception when a when-statement with no else makes no match

This commit is contained in:
Andrey Breslav
2013-10-18 18:34:54 +04:00
parent aacf133ef6
commit ea2b6e4546
10 changed files with 111 additions and 2 deletions
@@ -3725,7 +3725,17 @@ The "returned" value of try expression with no finally is either the last expres
}
if (!hasElse && nextCondition != null) {
v.mark(nextCondition);
throwNewException(CLASS_NO_PATTERN_MATCHED_EXCEPTION);
if (!isStatement) {
// a result is expected
if (Boolean.TRUE.equals(bindingContext.get(BindingContext.EXHAUSTIVE_WHEN, expression))) {
// when() is supposed to be exhaustive
throwNewException(CLASS_NO_PATTERN_MATCHED_EXCEPTION);
}
else {
// non-exhaustive when() with no else -> Unit must be expected
StackValue.putUnitInstance(v);
}
}
}
markLineNumber(expression);