fix one element struct unpacking

I think this broke when we decided that we want to not drop empty fields from layouts?
This commit is contained in:
Folkert 2021-01-21 21:40:04 +01:00
parent ef89ff15a1
commit df8ab829a6
4 changed files with 33 additions and 17 deletions

View file

@ -1250,24 +1250,12 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
index, index,
structure, structure,
wrapped: Wrapped::SingleElementRecord, wrapped: Wrapped::SingleElementRecord,
field_layouts,
.. ..
} => { } => {
match load_symbol_and_layout(env, scope, structure) { debug_assert_eq!(field_layouts.len(), 1);
(StructValue(argument), Layout::Struct(fields)) if fields.len() > 1 => debug_assert_eq!(*index, 0);
// TODO so sometimes a value gets Wrapped::SingleElementRecord load_symbol(env, scope, structure)
// but still has multiple fields...
{
env.builder
.build_extract_value(
argument,
*index as u32,
env.arena
.alloc(format!("struct_field_access_single_element{}", index)),
)
.unwrap()
}
(other, _) => other,
}
} }
AccessAtIndex { AccessAtIndex {

View file

@ -960,4 +960,27 @@ mod gen_tags {
|x: &i64| *x |x: &i64| *x
); );
} }
#[test]
fn newtype_wrapper() {
assert_evals_to!(
indoc!(
r#"
app "test" provides [ main ] to "./platform"
ConsList a : [ Nil, Cons a (ConsList a) ]
foo : ConsList I64 -> ConsList I64
foo = \t ->
when Delmin (Del t 0.0) is
Delmin (Del ry _) -> Cons 42 ry
main = foo Nil
"#
),
42,
&i64,
|x: &i64| *x
);
}
} }

View file

@ -1013,6 +1013,8 @@ fn path_to_expr_help<'a>(
debug_assert!(*index < field_layouts.len() as u64); debug_assert!(*index < field_layouts.len() as u64);
debug_assert_eq!(field_layouts.len(), 1);
let inner_layout = field_layouts[*index as usize].clone(); let inner_layout = field_layouts[*index as usize].clone();
let inner_expr = Expr::AccessAtIndex { let inner_expr = Expr::AccessAtIndex {
index: *index, index: *index,

View file

@ -3255,7 +3255,10 @@ pub fn with_hole<'a>(
match Wrapped::opt_from_layout(&record_layout) { match Wrapped::opt_from_layout(&record_layout) {
Some(result) => result, Some(result) => result,
None => Wrapped::SingleElementRecord, None => {
debug_assert_eq!(field_layouts.len(), 1);
Wrapped::SingleElementRecord
}
} }
}; };