mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
Change guard to DestructType
This commit is contained in:
parent
c9883be8a2
commit
43bca05cdb
4 changed files with 69 additions and 16 deletions
|
@ -941,7 +941,7 @@ fn canonicalize_field<'a>(
|
|||
|
||||
match field {
|
||||
// Both a label and a value, e.g. `{ name: "blah" }`
|
||||
LabeledValue(label, _, loc_expr) => {
|
||||
RequiredValue(label, _, loc_expr) => {
|
||||
let field_var = var_store.fresh();
|
||||
let (loc_can_expr, output) =
|
||||
canonicalize_expr(env, var_store, scope, loc_expr.region, &loc_expr.value);
|
||||
|
@ -954,6 +954,10 @@ fn canonicalize_field<'a>(
|
|||
)
|
||||
}
|
||||
|
||||
OptionalValue(_, _, _) => {
|
||||
todo!("TODO gracefully handle an optional field being used in an Expr");
|
||||
}
|
||||
|
||||
// A label with no value, e.g. `{ name }` (this is sugar for { name: name })
|
||||
LabelOnly(_) => {
|
||||
panic!("Somehow a LabelOnly record field was not desugared!");
|
||||
|
|
|
@ -44,7 +44,14 @@ pub struct RecordDestruct {
|
|||
pub var: Variable,
|
||||
pub label: Lowercase,
|
||||
pub symbol: Symbol,
|
||||
pub guard: Option<(Variable, Located<Pattern>)>,
|
||||
pub typ: DestructType,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum DestructType {
|
||||
Required,
|
||||
Optional(Variable),
|
||||
Guard(Variable, Located<Pattern>),
|
||||
}
|
||||
|
||||
pub fn symbols_from_pattern(pattern: &Pattern) -> Vec<Symbol> {
|
||||
|
@ -253,7 +260,7 @@ pub fn canonicalize_pattern<'a>(
|
|||
var: var_store.fresh(),
|
||||
label: Lowercase::from(label),
|
||||
symbol,
|
||||
guard: None,
|
||||
typ: DestructType::Required,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -271,7 +278,8 @@ pub fn canonicalize_pattern<'a>(
|
|||
}
|
||||
};
|
||||
}
|
||||
RecordField(label, loc_guard) => {
|
||||
|
||||
RequiredField(label, loc_guard) => {
|
||||
// a guard does not introduce the label into scope!
|
||||
let symbol = scope.ignore(label.into(), &mut env.ident_ids);
|
||||
let can_guard = canonicalize_pattern(
|
||||
|
@ -289,7 +297,7 @@ pub fn canonicalize_pattern<'a>(
|
|||
var: var_store.fresh(),
|
||||
label: Lowercase::from(label),
|
||||
symbol,
|
||||
guard: Some((var_store.fresh(), can_guard)),
|
||||
typ: DestructType::Guard(var_store.fresh(), can_guard),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -305,7 +313,8 @@ pub fn canonicalize_pattern<'a>(
|
|||
destructs,
|
||||
})
|
||||
}
|
||||
RecordField(_name, _loc_pattern) => {
|
||||
|
||||
RequiredField(_name, _loc_pattern) | OptionalField(_name, _loc_pattern) => {
|
||||
unreachable!("should have been handled in RecordDestructure");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue