leo icon indicating copy to clipboard operation
leo copied to clipboard

[Bug] Insufficient error handling for expressions with different types

Open dev-sptg opened this issue 2 years ago • 0 comments

🐛 Bug Report

The compiler does give a high-level error on expression. And does not stop on each subexpression error.

Code snippet to reproduce

let c16: bool = (1u32 & 123i16) == ((22u64 + 333i32 + "vvv") - 1i8 + 22u32 / 1i16 );

The code above gives error : MicrosoftTeams-image

From the expression below we can see that type was resolved to u64

(22u64 + 333i32 + "vvv")

and the same is relevant to this exression, it also equals u64.

((22u64 + 333i32 + "vvv") - 1i8 + 22u32 / 123i16);

The expression below resolved to type u32.

(1u32 & 123i16)

And as a result of both expressions, we receive type u32 == u64 and see compiler output - Error [ETYC0372003]: Expected type u64 but type u32 was found

Also, in the case when both expressions have the same type but in general, are not valid, the compiler does not give an error.

let c16: bool = ("123i32" & 123i16) == ("sss" / 1i8 - 1i8 + 22u32);

MicrosoftTeams-image (1)

For both expressions, types are resolved to string.

("123i32" & 123i16) 
("sss" / 1i8 - 1i8 + 22u32)

So the compiler did compare string with string and it does not give an error.

Expected Behavior

Leo compiler should give a more “pointed” span. It correctly rejects the code, and the span correctly points to an erroneous expression, but it would be better if it indicated a smaller erroneous subexpression.

Your Environment

  • testnet3 5021c7e
  • Rust 1.63.0
  • Windows 10

dev-sptg avatar Aug 23 '22 09:08 dev-sptg