re-wrap a named type in morphic spec generation

This commit is contained in:
Folkert 2023-04-02 18:44:39 +02:00
parent 2910024be5
commit c6de2c4a58
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 42 additions and 2 deletions

View file

@ -305,8 +305,8 @@ where
debug_assert_eq!(variant_types.len(), 1);
variant_types[0]
} else {
let data_type = builder.add_union_type(&variant_types)?;
let cell_type = builder.add_heap_cell_type();
let data_type = builder.add_union_type(&variant_types)?;
builder.add_tuple_type(&[cell_type, data_type])?
};
@ -1472,7 +1472,8 @@ fn expr_spec<'a>(
let _unit = builder.add_update(block, update_mode_var, heap_cell)?;
with_new_heap_cell(builder, block, union_data)
let value = with_new_heap_cell(builder, block, union_data)?;
builder.add_make_named(block, MOD_APP, type_name, value)
}
RuntimeErrorFunction(_) => {
let type_id = layout_spec(env, builder, interner, layout)?;

View file

@ -4421,3 +4421,42 @@ fn layout_cache_structure_with_multiple_recursive_structures() {
u8
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn reset_recursive_type_wraps_in_named_type() {
assert_evals_to!(
indoc!(
r###"
app "test" provides [main] to "./platform"
main : Str
main =
newList = mapLinkedList (Cons 1 (Cons 2 (Cons 3 Nil))) (\x -> x + 1)
printLinkedList newList Num.toStr
LinkedList a : [Cons a (LinkedList a), Nil]
mapLinkedList : LinkedList a, (a -> b) -> LinkedList b
mapLinkedList = \linkedList, f -> when linkedList is
Nil -> Nil
Cons x xs ->
s = if Bool.true then "true" else "false"
expect s == "true"
Cons (f x) (mapLinkedList xs f)
printLinkedList : LinkedList a, (a -> Str) -> Str
printLinkedList = \linkedList, f ->
when linkedList is
Nil -> "Nil"
Cons x xs ->
strX = f x
strXs = printLinkedList xs f
"Cons \(strX) (\(strXs))"
"###
),
RocStr::from("Cons 2 (Cons 3 (Cons 4 (Nil)))"),
RocStr
);
}