mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-11 18:58:24 +03:00
fix list elementes being cloned to the wrong place
This commit is contained in:
parent
12350410df
commit
dca1c665ae
@ -1042,9 +1042,13 @@ fn build_clone_builtin<'a, 'ctx, 'env>(
|
||||
|
||||
let elements_width = bd.build_int_mul(element_width, len, "elements_width");
|
||||
|
||||
// We clone the elements into the extra_offset address.
|
||||
let _ = offset;
|
||||
let elements_start_offset = cursors.extra_offset;
|
||||
|
||||
if layout_interner.safe_to_memcpy(elem) {
|
||||
// NOTE we are not actually sure the dest is properly aligned
|
||||
let dest = pointer_at_offset(bd, env.context.i8_type(), ptr, offset);
|
||||
let dest = pointer_at_offset(bd, env.context.i8_type(), ptr, elements_start_offset);
|
||||
let src = bd.build_pointer_cast(
|
||||
elements,
|
||||
env.context.i8_type().ptr_type(AddressSpace::Generic),
|
||||
@ -1052,11 +1056,8 @@ fn build_clone_builtin<'a, 'ctx, 'env>(
|
||||
);
|
||||
bd.build_memcpy(dest, 1, src, 1, elements_width).unwrap();
|
||||
|
||||
bd.build_int_add(offset, elements_width, "new_offset")
|
||||
bd.build_int_add(elements_start_offset, elements_width, "new_offset")
|
||||
} else {
|
||||
// We cloned the elements into the extra_offset address.
|
||||
let elements_start_offset = cursors.extra_offset;
|
||||
|
||||
let element_type = basic_type_from_layout(env, layout_interner, elem);
|
||||
let elements = bd.build_pointer_cast(
|
||||
elements,
|
||||
|
@ -975,4 +975,68 @@ mod test {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn foobar() {
|
||||
run_expect_test(
|
||||
indoc!(
|
||||
r#"
|
||||
interface Test exposes [] imports []
|
||||
|
||||
expect
|
||||
actual : { headers: List U8, body: List U8, x: List U8 }
|
||||
actual = {
|
||||
body: [],
|
||||
headers: [],
|
||||
x: [],
|
||||
}
|
||||
|
||||
expected : { headers: List U8, body: List U8, x: List U8 }
|
||||
expected = {
|
||||
body: [ 42, 43, 44 ],
|
||||
headers: [15, 16, 17],
|
||||
x: [115, 116, 117],
|
||||
}
|
||||
actual == expected
|
||||
"#
|
||||
),
|
||||
indoc!(
|
||||
r#"
|
||||
This expectation failed:
|
||||
|
||||
3│> expect
|
||||
4│> actual : { headers: List U8, body: List U8, x: List U8 }
|
||||
5│> actual = {
|
||||
6│> body: [],
|
||||
7│> headers: [],
|
||||
8│> x: [],
|
||||
9│> }
|
||||
10│>
|
||||
11│> expected : { headers: List U8, body: List U8, x: List U8 }
|
||||
12│> expected = {
|
||||
13│> body: [ 42, 43, 44 ],
|
||||
14│> headers: [15, 16, 17],
|
||||
15│> x: [115, 116, 117],
|
||||
16│> }
|
||||
17│> actual == expected
|
||||
|
||||
When it failed, these variables had these values:
|
||||
|
||||
actual : {
|
||||
body : List (Int Unsigned8),
|
||||
headers : List (Int Unsigned8),
|
||||
x : List (Int Unsigned8),
|
||||
}
|
||||
actual = { body: [], headers: [], x: [] }
|
||||
|
||||
expected : {
|
||||
body : List (Int Unsigned8),
|
||||
headers : List (Int Unsigned8),
|
||||
x : List (Int Unsigned8),
|
||||
}
|
||||
expected = { body: [42, 43, 44], headers: [15, 16, 17], x: [115, 116, 117] }
|
||||
"#
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user