PistonDevelopers / dyon

A rusty dynamically typed scripting language
Apache License 2.0
1.77k stars 55 forks source link

Panic in function returning its only argument #654

Open Snarpix opened 4 years ago

Snarpix commented 4 years ago

I have experienced panic in dyon 0.44.0 in following code:

use std::sync::Arc;
use dyon::{load_str, error, Call, Module, Runtime, RustObject};

#[derive(Debug)]
struct Test{}

fn main() {
    let mut module = Module::new();
    error(load_str("main.dyon", Arc::new(r#"
        fn test_func(obj: 'return) -> {
            return obj
        }
    "#.into()), &mut module));
    let ref module = Arc::new(module);

    let j = Test{};

    // Call function that returns Rust object.
    let call = Call::new("test_func").rust(j);
    match call.run_ret::<RustObject>(&mut Runtime::new(), module) {
        Ok(answer) => {println!("{:?}", answer.lock().unwrap().downcast_ref::<Test>());}
        Err(err) => {error(Err(err));}
    }
}

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 1', dyon-0.44.0/src/runtime/mod.rs:108:32

It may be related to comment in runtime/mod.rs:1371

            // TODO: Could return the last value on the stack.
            //       Requires .pop_fn delayed after.

Is this a bug, or am I doing something wrong?