diff --git a/compiler/gen/src/llvm/build.rs b/compiler/gen/src/llvm/build.rs index da1b8a66ba..c1fc294964 100644 --- a/compiler/gen/src/llvm/build.rs +++ b/compiler/gen/src/llvm/build.rs @@ -1250,24 +1250,12 @@ pub fn build_exp_expr<'a, 'ctx, 'env>( index, structure, wrapped: Wrapped::SingleElementRecord, + field_layouts, .. } => { - match load_symbol_and_layout(env, scope, structure) { - (StructValue(argument), Layout::Struct(fields)) if fields.len() > 1 => - // TODO so sometimes a value gets Wrapped::SingleElementRecord - // 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, - } + debug_assert_eq!(field_layouts.len(), 1); + debug_assert_eq!(*index, 0); + load_symbol(env, scope, structure) } AccessAtIndex { diff --git a/compiler/gen/tests/gen_tags.rs b/compiler/gen/tests/gen_tags.rs index 6f7d0674d7..0f547ed3e2 100644 --- a/compiler/gen/tests/gen_tags.rs +++ b/compiler/gen/tests/gen_tags.rs @@ -960,4 +960,27 @@ mod gen_tags { |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 + ); + } } diff --git a/compiler/mono/src/decision_tree.rs b/compiler/mono/src/decision_tree.rs index ac1e9bd827..be611e55e9 100644 --- a/compiler/mono/src/decision_tree.rs +++ b/compiler/mono/src/decision_tree.rs @@ -1013,6 +1013,8 @@ fn path_to_expr_help<'a>( 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_expr = Expr::AccessAtIndex { index: *index, diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index b18f9b070a..fac7fc7ef2 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -3255,7 +3255,10 @@ pub fn with_hole<'a>( match Wrapped::opt_from_layout(&record_layout) { Some(result) => result, - None => Wrapped::SingleElementRecord, + None => { + debug_assert_eq!(field_layouts.len(), 1); + Wrapped::SingleElementRecord + } } };