WhileyCompiler icon indicating copy to clipboard operation
WhileyCompiler copied to clipboard

Duplicate Error Messages

Open DavePearce opened this issue 6 years ago • 1 comments

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.

DavePearce avatar Feb 15 '19 02:02 DavePearce

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.

DavePearce avatar Feb 19 '19 03:02 DavePearce