mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
make newtype wrappers explicit in pattern code
This commit is contained in:
parent
01f6433556
commit
61c9de91dc
4 changed files with 205 additions and 86 deletions
|
@ -425,6 +425,21 @@ fn test_at_path<'a>(
|
|||
});
|
||||
}
|
||||
|
||||
NewtypeDestructure {
|
||||
tag_name,
|
||||
arguments,
|
||||
} => {
|
||||
let tag_id = 0;
|
||||
let union = Union::newtype_wrapper(tag_name.clone(), arguments.len());
|
||||
|
||||
all_tests.push(IsCtor {
|
||||
tag_id,
|
||||
tag_name: tag_name.clone(),
|
||||
union,
|
||||
arguments: arguments.to_vec(),
|
||||
});
|
||||
}
|
||||
|
||||
AppliedTag {
|
||||
tag_name,
|
||||
tag_id,
|
||||
|
@ -565,6 +580,43 @@ fn to_relevant_branch_help<'a>(
|
|||
_ => None,
|
||||
},
|
||||
|
||||
NewtypeDestructure {
|
||||
tag_name,
|
||||
arguments,
|
||||
..
|
||||
} => match test {
|
||||
IsCtor {
|
||||
tag_name: test_name,
|
||||
tag_id: test_id,
|
||||
..
|
||||
} if &tag_name == test_name => {
|
||||
let tag_id = 0;
|
||||
debug_assert_eq!(tag_id, *test_id);
|
||||
|
||||
let sub_positions =
|
||||
arguments
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(index, (pattern, _))| {
|
||||
let mut new_path = path.to_vec();
|
||||
new_path.push(PathInstruction {
|
||||
index: index as u64,
|
||||
tag_id,
|
||||
});
|
||||
(new_path, Guard::NoGuard, pattern)
|
||||
});
|
||||
start.extend(sub_positions);
|
||||
start.extend(end);
|
||||
|
||||
Some(Branch {
|
||||
goal: branch.goal,
|
||||
patterns: start,
|
||||
})
|
||||
}
|
||||
|
||||
_ => None,
|
||||
},
|
||||
|
||||
AppliedTag {
|
||||
tag_name,
|
||||
tag_id,
|
||||
|
@ -750,6 +802,7 @@ fn needs_tests(pattern: &Pattern) -> bool {
|
|||
Identifier(_) | Underscore => false,
|
||||
|
||||
RecordDestructure(_, _)
|
||||
| NewtypeDestructure { .. }
|
||||
| AppliedTag { .. }
|
||||
| BitLiteral { .. }
|
||||
| EnumLiteral { .. }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue