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

Closure Type #21

Closed
MinusGix opened this issue Sep 6, 2020 · 1 comment
Closed

Closure Type #21

MinusGix opened this issue Sep 6, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@MinusGix
Copy link
Contributor

MinusGix commented Sep 6, 2020

How does one receive a closure as a value? Ex:

use rune_testing::*;
fn main() -> runestick::Result<()> {
    let function: Function = rune! {
        Function => r#"fn main() {
            |a, b| a + b
        }"#
    };
    println!("{}", function.call::<(i64, i64), i64>((1, 3))?);
    println!("{}", function.call::<(i64, i64), i64>((2, 6))?);
    Ok(())
}

Would panic with: thread 'main' panicked at 'program to run successfully: VmError { kind: Expected { expected: StaticType(StaticType { name: "Function", hash: Hash(0x45b788b02e7f231c) }), actual: Hash(Hash(0x9aa62663879132fb)) } }', src/main.rs:4:30
Expected behavior: Being able to receive the closure and call it.
(My main usecase for storing closures would be for callbacks, ex: a button being pressed, so somewhat similar to the example)

@udoprog
Copy link
Collaborator

udoprog commented Sep 7, 2020

Thanks for the report!

This looks like an issue with a recently introduced optimization. Closures which do not capture anything from their environment are treated like function. In this case the value being pushed is being pushed as a type, rather than a function. Fix coming up!

@udoprog udoprog added the bug Something isn't working label Sep 7, 2020
@udoprog udoprog closed this as completed in 7130c9b Sep 7, 2020
@udoprog udoprog added changelog Issue has been added to the changelog and removed changelog Issue has been added to the changelog labels Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants