Skip to content

register_fn_with_ctx does not supply context for async functions #676

Description

@kilesduli

Minimal reproduction:

  use steel::{
      SteelVal,
      steel_vm::{engine::Engine, register_fn::RegisterFn},
  };

  async fn add_with_context(ctx: i32, value: i32) -> i32 {
      ctx + value
  }

  fn main() {
      let mut engine = Engine::new();

      engine.register_value("*ctx*", SteelVal::IntV(10));
      engine.register_fn_with_ctx(
          "*ctx*",
          "add-with-context",
          add_with_context,
      );

      let result = engine.run("(add-with-context 1)");
      println!("{result:?}");
  }
Err(SteelErr { repr: Repr { kind: ArityMismatch, message: "add-with-context expected 2 argument, got 1", span: Some(1..17), stack_trace: Some(DehydratedStackTrace { stack_trace: [] }) } })

Seems supply_context_arg in impl RegisterValue for Engine only handle SteelVal::BoxedFunction

impl RegisterValue for Engine {
fn register_value_inner(&mut self, name: &str, value: SteelVal) -> &mut Self {
let idx = self.virtual_machine.compiler.write().register(name);
self.virtual_machine.insert_binding(idx, value);
self
}
fn supply_context_arg(&mut self, ctx: &'static str, name: &'static str) -> &mut Self {
if let Ok(existing) = self.extract_value(name) {
if let SteelVal::BoxedFunction(f) = &existing {
let func = generate_function(self, &SteelString::from(ctx), &existing, f);
self.register_value(name, func);
}
}
self
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions