rhaiscript / rhai

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

Panic: Entered unreachable code when using Dynamic::into_shared() #832

Closed MolotovCherry closed 8 months ago

MolotovCherry commented 8 months ago

Using the following code, I am able to cause an unreachable code panic

I don't know if I'm just perhaps missing something here, or doing something I'm not supposed to, but I am indeed able to get this to panic at runtime if I attempt to write to the variable

let map: Dynamic = Map::new().into();
let map = map.into_shared();

#[allow(deprecated)]
engine.on_var(move |name, _, _| match name {
    "V" => Ok(Some(map.clone())),
    _ => Ok(None),
});

Rhai code:

// not ok
V.a = "";
// ok
V = #{"a": ""};

// funnily enough, this is also ok
V.foo();
fn foo() {
    this.a = "";
}

Panic

Message:  internal error: entered unreachable code: `get_indexed_mut` cannot handle shared values
Location: <snip>\.cargo\registry\src\index.crates.io-6f17d22bba15001f\rhai-1.17.1\src\eval\chaining.rs:320
schungx commented 8 months ago

Yes, this should be a bug. Thanks for catching.

Luckily I put in a panic to catch the cases I never think would happen.

schungx commented 8 months ago

I think I fixed it.

It is in the latest drop, so you can try it out.

Do you need it urgently? Can you wait till the next major release?

MolotovCherry commented 8 months ago

I think I fixed it.

It is in the latest drop, so you can try it out.

Do you need it urgently? Can you wait till the next major release?

Thank you for the quick fix! I think I can hold out until next release~ (Though an earlier release is welcome too, but I can wait)

schungx commented 8 months ago

You can point to this repo to test out the fix.

MolotovCherry commented 8 months ago

Confirmed, it's working properly now! Thanks again for the quick attention to this!