mutagen icon indicating copy to clipboard operation
mutagen copied to clipboard

fails to parse multiple arithmetic operators without parentheses

Open bblum opened this issue 5 years ago • 1 comments

10 #[mutate]
11 pub fn add_five(i: usize) -> usize {
12     i + 4 + 1
13 }

fails to cargo test with:

error: custom attribute panicked
   --> src/test.rs:10:1
    |
157 | #[mutate]
    | ^^^^^^^^^
    |
    = help: message: expected expression

error: aborting due to previous error

If you change the plus to a minus, it produces instead

error[E0308]: mismatched types
   --> src/test.rs:10:1
    |
157 | #[mutate]
    | ^^^^^^^^^ expected (), found usize
    |
    = note: expected type `()`
               found type `usize`

error[E0308]: mismatched types
   --> src/test.rs:10:1
    |
157 | #[mutate]
    | ^^^^^^^^^- help: try adding a semicolon: `;`
    | |
    | expected (), found usize
    |
    = note: expected type `()`
               found type `usize`

error[E0600]: cannot apply unary operator `-` to type `usize`
   --> src/test.rs:10:1
    |
157 | #[mutate]
    | ^^^^^^^^^ cannot apply unary operator `-`
    |
    = note: unsigned values cannot be negated

error: aborting due to 3 previous errors

With multiply as the second operation instead:

error[E0271]: type mismatch resolving `<i32 as mutagen::MulDiv>::Output == usize`
   --> src/test.rs:10:1
    |
157 | #[mutate]
    | ^^^^^^^^^ expected i32, found usize

error: aborting due to previous error

bblum avatar Apr 12 '19 23:04 bblum

this one can be fixed by putting parens around the #left $op_found #right in the definition of fold_binary!, although i'm honestly not sure why.

bblum avatar Apr 18 '19 04:04 bblum