Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutation incorrectly infers integer literals #157

Open
elichai opened this issue Jan 23, 2020 · 4 comments
Open

Mutation incorrectly infers integer literals #157

elichai opened this issue Jan 23, 2020 · 4 comments

Comments

@elichai
Copy link

elichai commented Jan 23, 2020

Minimally reproducible example:

use mutagen::mutate;

#[mutate]
fn hi(mut ret: i64) -> i64 {
    let sh = if ret > 5 {
        0
    } else {
        8
    };
    ret += sh - 1;
    ret
}

fn main() {
    println!("Hello, world! {}", hi(500));
}

Without the macro it compiles fine. with the macro it returns the following:

error[E0277]: cannot add-assign `i32` to `i64`
  --> src/main.rs:11:9
   |
11 |     ret += sh - 1;
   |         ^^ no implementation for `i64 += i32`
   |
   = help: the trait `std::ops::AddAssign<i32>` is not implemented for `i64`

mutagen dep: git+https://github.com/llogiq/mutagen.git#99d9e12bf4e28e3a734b36f216650cec09a54c6c

@samuelpilz
Copy link
Contributor

Types are not corrupted. They are incorrectly inferred. Through the code that is generated by mutagen, Rust can no longer do correct propagation of types and the default type for the integer 1 is chosen. Setting an explicit type to the variable sh fixes this issue.

This is a general problem. There are code snippets where the macro has not enough information to perform a transformation that never vail to infer correct types.

It is possible to fix the given snippet and I will try to extend the current detection mechanism for integer expressions.

@elichai elichai changed the title Mutation literals corrupts types Mutation incorrectly inferres integer literals Jan 23, 2020
@elichai
Copy link
Author

elichai commented Jan 23, 2020

Types are not corrupted. They are incorrectly inferred.

Right sorry, English isn't my native language :) Thanks.

@elichai elichai changed the title Mutation incorrectly inferres integer literals Mutation incorrectly infers integer literals Jan 23, 2020
@llogiq
Copy link
Owner

llogiq commented Jan 23, 2020

@power-fungus this used to work. What changed?

@samuelpilz
Copy link
Contributor

Indeed. I will investigate this. Stay tuned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants