update from review comments

This commit is contained in:
Luke Boswell 2024-03-21 15:46:14 +11:00
parent e74501981e
commit a394f1b4cf
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
3 changed files with 25 additions and 25 deletions

View file

@ -597,22 +597,16 @@ impl<'a> Defs<'a> {
// We need the value index to know if it is the first
pub fn search_suffixed_defs(&self) -> Option<(usize, usize)> {
for (tag_index, tag) in self.tags.iter().enumerate() {
let index = match tag.split() {
Ok(_) => continue,
Err(value_index) => value_index.index(),
};
if let Err(value_index) = tag.split() {
let index = value_index.index();
match &self.value_defs[index] {
ValueDef::Body(_, expr) => match expr.value {
Expr::Apply(sub_expr, _, _) => match sub_expr.value {
Expr::Suffixed(_) => {
if let ValueDef::Body(_, expr) = &self.value_defs[index] {
if let Expr::Apply(sub_expr, _, _) = expr.value {
if let Expr::Suffixed(_) = sub_expr.value {
return Some((tag_index, index));
}
_ => continue,
},
_ => continue,
},
_ => continue,
}
}
}
}
@ -620,23 +614,28 @@ impl<'a> Defs<'a> {
}
// For desugaring Suffixed Defs we need to split the defs around the Suffixed value
pub fn split_values_either_side_of(&self, index: usize) -> (Self, Self) {
pub fn split_values_either_side_of(&self, index: usize) -> SplitDefsAround {
let mut before = self.clone();
let mut after = self.clone();
before.tags = self.tags[0..index].to_vec();
if index + 1 > self.tags.len() {
if index >= self.tags.len() {
after.tags = self.tags.clone();
after.tags.clear();
} else {
after.tags = self.tags[(index + 1)..].to_vec();
}
(before, after)
SplitDefsAround { before, after }
}
}
pub struct SplitDefsAround<'a> {
pub before: Defs<'a>,
pub after: Defs<'a>,
}
/// Should always be a zero-argument `Apply`; we'll check this in canonicalization
pub type AbilityName<'a> = Loc<TypeAnnotation<'a>>;