rhaiscript / rhai

Rhai - An embedded scripting language for Rust.
https://crates.io/crates/rhai
Apache License 2.0
3.8k stars 177 forks source link

Panic 'op-assigment operator' #510

Closed lroobrou closed 2 years ago

lroobrou commented 2 years ago

After bumping rhai from 1.3.0 to 1.4.0, I received a panic when loading some scripts, with the following message.

thread 'main' panicked at 'op-assignment operator'

The panic occurs at src/ast/stmt.rs:49:14. I turns out that assignments of the form var = var + integer are causing this. Here is an example program that panics with 1.4.0, which runs just fine with 1.3.0.

extern crate rhai;

use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    let engine = rhai::Engine::new();
    let result: i64 = engine.eval(
        r#"
        let a = 0;
        a = a + 1;  // panics
        a
        "#,
    )?;

    println!("result = {}", result);

    Ok(())
}
schungx commented 2 years ago

Yes, good catch. Dunno how this slipped through...

I'll put out a bug-fix version to fix this soon. In the meantime, you can use x += 1 which should work fine!

schungx commented 2 years ago

1.4.1 is published which should contain this bug fix, among others.

Thanks for raising this. Let me know if the new version solves your problem.

lroobrou commented 2 years ago

Yes, problem solved. :)