aeternity / aesophia

Stand alone compiler for the Sophia smart contract language
https://docs.aeternity.com/aesophia
ISC License
52 stars 19 forks source link

Add compiler warnings #346

Closed ghallak closed 2 years ago

ghallak commented 3 years ago

Currently added warnings:

Currently supported options:

Things that still need to be done:

Testing:

ghallak commented 3 years ago

@hanssv @radrow I'm looking for a way to properly report the warnings. Right now, the warnings are all stored in an ets_table called warnings in the aeso_ast_infer_types.erl file.

Do you think I should keep forwarding the warnings as strings upwards until they get to the aeso_compiler:from_string function and then I can return them along with the compilation result? or is there another way to do that?

radrow commented 3 years ago

I think that warnings should be returned as renderable structures as a result of the compilation/infer function

hanssv commented 3 years ago

Yes, keeping them in some warning structure (similar to the errors) and passing them upwards sounds like the best alternative. Then we can present them, or return them (or ignore them) according to options I guess.

ghallak commented 3 years ago

For negative spends and division by zero, the warning will only show when using a literal.

function f() =
  let x = 1 / 0  // this is a warning

  let zero = 0
  let y = 1 / zero  // no warning will show here

  let z = 1 / (1 - 1)  // no warning will show here

I think it won't be very difficult to add warning for the second case 1 / zero since this will only need to lookup the value of the variables zero, but the third case will requires evaluating the expression 1 - 1, which will make things more complicated and I'm not sure if I should try to add that.

dincho commented 3 years ago

but the third case will requires evaluating the expression 1 - 1, which will make things more complicated and I'm not sure if I should try to add that.

I guess if the compiler have a optimization phase to evaluate that and you run the warning check in a step/phase after it it would be covered by case 1

radrow commented 3 years ago

there could be a second pass of warning check after additional constant propagation

radrow commented 2 years ago

Would be nice to reflect it in the cli and http interface too

radrow commented 2 years ago

@nikita-fuchs would be great to see it working in aestudio :)

nikita-fuchs commented 2 years ago

@nikita-fuchs would be great to see it working in aestudio :)

dayumn, thanks for bringing this up.