Skip to content

Commit a290f17

Browse files
bors[bot]Marwes
andauthored
Merge #850
850: fix: Convert rust tuples such that they can be used polymorphically r=Marwes a=Marwes Fixes #848 Co-authored-by: Markus Westerlind <[email protected]>
2 parents db97fa6 + 6c4d573 commit a290f17

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

tests/api.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,18 @@ fn use_type_from_type_field() {
339339
assert_eq!(actual, Test::B("abc".to_string()));
340340
}
341341

342+
#[test]
343+
fn use_rust_created_tuple_as_polymorphic() {
344+
let _ = ::env_logger::try_init();
345+
let test = r"\x -> x._0";
346+
let mut vm = make_vm();
347+
load_script(&mut vm, "test", test).unwrap_or_else(|err| panic!("{}", err));
348+
349+
let mut f: FunctionRef<fn((i32, String)) -> VmInt> = vm.get_global("test").unwrap();
350+
let result = f.call((1, "".to_string())).unwrap();
351+
assert_eq!(result, 1);
352+
}
353+
342354
#[test]
343355
fn use_rust_created_record_as_polymorphic() {
344356
let _ = ::env_logger::try_init();

vm/src/api/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,13 @@ macro_rules! define_tuple {
16871687
$id.push(context)?;
16881688
)+
16891689
let len = count!($($id),+);
1690-
context.context().push_new_data(0, len)?;
1690+
let thread = context.thread();
1691+
#[allow(unused_assignments)]
1692+
let field_names = {
1693+
let mut i = 0;
1694+
[$(thread.global_env().intern(&format!("_{}", { let _ = $id; let x = i; i += 1; x }))?),*]
1695+
};
1696+
context.context().push_new_record(len, &field_names)?;
16911697
Ok(())
16921698
}
16931699
}

0 commit comments

Comments
 (0)