mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
create NullableUnion in some cases
This commit is contained in:
parent
b47ccb20fd
commit
51cad15399
3 changed files with 41 additions and 2 deletions
|
@ -1007,6 +1007,22 @@ fn path_to_expr_help<'a>(
|
|||
Layout::Union(layouts) | Layout::RecursiveUnion(layouts) => {
|
||||
layouts[*tag_id as usize]
|
||||
}
|
||||
Layout::NullableUnion {
|
||||
nullable_id,
|
||||
nullable_layout,
|
||||
foo: layouts,
|
||||
..
|
||||
} => {
|
||||
use std::cmp::Ordering;
|
||||
match (*tag_id as usize).cmp(&(*nullable_id as usize)) {
|
||||
Ordering::Equal => {
|
||||
&*env.arena.alloc([Layout::Builtin(nullable_layout.clone())])
|
||||
}
|
||||
Ordering::Less => layouts[*tag_id as usize],
|
||||
Ordering::Greater => layouts[*tag_id as usize - 1],
|
||||
}
|
||||
}
|
||||
|
||||
Layout::Struct(layouts) => layouts,
|
||||
other => env.arena.alloc([other.clone()]),
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue