Support box/unbox for types that are typically only on the stack

Closes #2786
This commit is contained in:
Ayaz Hafiz 2022-04-09 16:21:41 -04:00
parent ebb03f60dd
commit a102a7497e
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 53 additions and 5 deletions

View file

@ -3275,3 +3275,47 @@ fn box_and_unbox_string() {
RocStr
)
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn box_and_unbox_num() {
assert_evals_to!(
indoc!(
r#"
Box.unbox (Box.box (123u8))
"#
),
123,
u8
)
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn box_and_unbox_record() {
assert_evals_to!(
indoc!(
r#"
Box.unbox (Box.box { a: 15u8, b: 27u8 })
"#
),
(15, 27),
(u8, u8)
)
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn box_and_unbox_tag_union() {
assert_evals_to!(
indoc!(
r#"
v : [ A U8, B U8 ] # usually stack allocated
v = B 27u8
Box.unbox (Box.box v)
"#
),
(27, 1),
(u8, u8)
)
}