mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
remove EmptyStruct from wrapper
This commit is contained in:
parent
ab8e0c756d
commit
4bbaa007f3
3 changed files with 43 additions and 7 deletions
|
@ -885,10 +885,6 @@ fn expr_spec(
|
|||
let value_id = env.symbols[structure];
|
||||
|
||||
match wrapped {
|
||||
Wrapped::EmptyRecord => {
|
||||
// this is a unit value
|
||||
builder.add_make_tuple(block, &[])
|
||||
}
|
||||
Wrapped::SingleElementRecord => {
|
||||
// builder.add_get_tuple_field(block, value_id, *index as u32)
|
||||
Ok(env.symbols[structure])
|
||||
|
|
|
@ -1016,7 +1016,6 @@ pub enum Literal<'a> {
|
|||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum Wrapped {
|
||||
EmptyRecord,
|
||||
SingleElementRecord,
|
||||
RecordOrSingleTagUnion,
|
||||
}
|
||||
|
@ -1036,7 +1035,7 @@ impl Wrapped {
|
|||
pub fn opt_from_layout(layout: &Layout<'_>) -> Option<Self> {
|
||||
match layout {
|
||||
Layout::Struct(fields) => match fields.len() {
|
||||
0 => Some(Wrapped::EmptyRecord),
|
||||
0 => unreachable!(),
|
||||
1 => Some(Wrapped::SingleElementRecord),
|
||||
_ => Some(Wrapped::RecordOrSingleTagUnion),
|
||||
},
|
||||
|
@ -1048,7 +1047,7 @@ impl Wrapped {
|
|||
Recursive(tags) | NonRecursive(tags) => match tags {
|
||||
[] => todo!("how to handle empty tag unions?"),
|
||||
[single] => match single.len() {
|
||||
0 => Some(Wrapped::EmptyRecord),
|
||||
0 => unreachable!(),
|
||||
1 => Some(Wrapped::SingleElementRecord),
|
||||
_ => Some(Wrapped::RecordOrSingleTagUnion),
|
||||
},
|
||||
|
|
|
@ -2488,3 +2488,44 @@ fn hit_unresolved_type_variable() {
|
|||
RocStr
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pattern_match_empty_record() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [ main ] to "./platform"
|
||||
|
||||
main : I64
|
||||
main =
|
||||
when {} is
|
||||
{} -> 0
|
||||
|
||||
"#
|
||||
),
|
||||
0,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pattern_match_unit_tag() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [ main ] to "./platform"
|
||||
|
||||
unit : [ Unit ]
|
||||
unit = Unit
|
||||
|
||||
main : I64
|
||||
main =
|
||||
when unit is
|
||||
Unit -> 0
|
||||
|
||||
"#
|
||||
),
|
||||
0,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue