WhileyCompiler
WhileyCompiler copied to clipboard
Duplicate Error Messages
There are various situations where we can end up with duplicate error messages. The following is a simple example:
function f(int z) -> int:
if z:
return 1
return 0
This currently yields the following error messages:
tests/invalid/If_Invalid_1.whiley:2: expected type bool, found int
if z:
^
tests/invalid/If_Invalid_1.whiley:2: expected type bool, found int
if z:
^
The problem arises because, when type checking if statements, checkCondition is called twice: once in the positive position and once in the negative position. Since the type of z above is not affected by its position we end up with it being reported twice.
Another example arises in AmbiguousCoercionCheck and test TypeEquals_Invalid_7:
function f(int|null x) -> (bool|null r):
//
if x is int && x >= 0:
return false
else:
return x
Which currently reports this error:
TypeEquals_Invalid_7.whiley:6: expected type bool|null, found ((int|null)-int)|((int|null)&int)
return x
^
TypeEquals_Invalid_7.whiley:6: ambiguous coercion required (null|int to bool|null)
return x
^
Realistically, we should be able to spot that this is invalid an just abort the check altogether.