mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
alignment in pattern match on single element tag union
This commit is contained in:
parent
ccd2e0ecf4
commit
69734e837e
2 changed files with 46 additions and 1 deletions
|
@ -760,7 +760,7 @@ mod gen_tags {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn alignment_in_single_tag() {
|
fn alignment_in_single_tag_construction() {
|
||||||
assert_evals_to!(indoc!("Three (1 == 1) 32"), (32i64, true), (i64, bool));
|
assert_evals_to!(indoc!("Three (1 == 1) 32"), (32i64, true), (i64, bool));
|
||||||
|
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
|
@ -769,4 +769,35 @@ mod gen_tags {
|
||||||
(i64, bool, u8)
|
(i64, bool, u8)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn alignment_in_single_tag_pattern_match() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r"#
|
||||||
|
x = Three (1 == 1) 32
|
||||||
|
|
||||||
|
when x is
|
||||||
|
Three bool int ->
|
||||||
|
{ bool, int }
|
||||||
|
#"
|
||||||
|
),
|
||||||
|
(32i64, true),
|
||||||
|
(i64, bool)
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r"#
|
||||||
|
x = Three (1 == 1) (if True then Red else if True then Green else Blue) 32
|
||||||
|
|
||||||
|
when x is
|
||||||
|
Three bool color int ->
|
||||||
|
{ bool, color, int }
|
||||||
|
#"
|
||||||
|
),
|
||||||
|
(32i64, true, 2u8),
|
||||||
|
(i64, bool, u8)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5313,6 +5313,20 @@ pub fn from_can_pattern<'a>(
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut arguments = arguments.clone();
|
||||||
|
|
||||||
|
arguments.sort_by(|arg1, arg2| {
|
||||||
|
let ptr_bytes = 8;
|
||||||
|
|
||||||
|
let layout1 = layout_cache.from_var(env.arena, arg1.0, env.subs).unwrap();
|
||||||
|
let layout2 = layout_cache.from_var(env.arena, arg2.0, env.subs).unwrap();
|
||||||
|
|
||||||
|
let size1 = layout1.alignment_bytes(ptr_bytes);
|
||||||
|
let size2 = layout2.alignment_bytes(ptr_bytes);
|
||||||
|
|
||||||
|
size2.cmp(&size1)
|
||||||
|
});
|
||||||
|
|
||||||
let mut mono_args = Vec::with_capacity_in(arguments.len(), env.arena);
|
let mut mono_args = Vec::with_capacity_in(arguments.len(), env.arena);
|
||||||
for ((_, loc_pat), layout) in arguments.iter().zip(field_layouts.iter()) {
|
for ((_, loc_pat), layout) in arguments.iter().zip(field_layouts.iter()) {
|
||||||
mono_args.push((
|
mono_args.push((
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue