diff --git a/compiler/hash-repr/src/write.rs b/compiler/hash-repr/src/write.rs index a2ec96ee2..01e005c75 100644 --- a/compiler/hash-repr/src/write.rs +++ b/compiler/hash-repr/src/write.rs @@ -338,8 +338,10 @@ impl BoxRow { return; } - // Insert an empty box to fill in the missing gap. - if width - current_width > 2 { + // For singletons, insert an empty box to fill in the missing gap. + let singleton = self.contents.len() == 1; + + if singleton && width - current_width > 2 { let empty_width = width - current_width - 1; self.widths.push(empty_width); self.contents.push(BoxContent::new_empty(empty_width)); diff --git a/tests/cases/typecheck/enums/discriminants/valid.hash b/tests/cases/typecheck/enums/discriminants/valid.hash index 7579b4ccc..5fb1a473a 100644 --- a/tests/cases/typecheck/enums/discriminants/valid.hash +++ b/tests/cases/typecheck/enums/discriminants/valid.hash @@ -61,6 +61,10 @@ Variants := enum( #layout_of Empty := enum(); - +#layout_of +Boon := enum( + Foo(x: i32, y: i32), + Faz(z: f64), +); main := () => {} diff --git a/tests/cases/typecheck/enums/discriminants/valid.stdout b/tests/cases/typecheck/enums/discriminants/valid.stdout index 365cc1b86..d2fb538bd 100644 --- a/tests/cases/typecheck/enums/discriminants/valid.stdout +++ b/tests/cases/typecheck/enums/discriminants/valid.stdout @@ -102,3 +102,20 @@ info: Layout of `!` (size=0b align=1b): │ align: 1b │ └────────────┘ +info: Layout of `Boon` (size=16b align=8b): +┌──────────────┬─────────────────────────┐ +│ 4b tag (u32) │ │ +├──────────────┼────────────┬────────────┤ +│ Foo │ x: i32 │ y: i32 │ +│ │ │ │ +│ 0 │ size: 4b │ size: 4b │ +│ │ offset: 4b │ offset: 8b │ +│ │ align: 4b │ align: 4b │ +├──────────────┼────────┬───┴────────────┤ +│ Faz │ 4b pad │ z: f64 │ +│ │ │ │ +│ 1 │ ## │ size: 8b │ +│ │ ## │ offset: 8b │ +│ │ ## │ align: 8b │ +└──────────────┴────────┴────────────────┘ +