mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
optional fields improvements
This commit is contained in:
parent
48aebc5c59
commit
b45b39af5e
14 changed files with 329 additions and 47 deletions
|
@ -227,24 +227,28 @@ pub fn constrain_pattern(
|
|||
|
||||
constrain_pattern(env, &loc_guard.value, loc_guard.region, expected, state);
|
||||
|
||||
RecordField::Required(pat_type)
|
||||
RecordField::Demanded(pat_type)
|
||||
}
|
||||
DestructType::Optional(expr_var, loc_expr) => {
|
||||
state.constraints.push(Constraint::Pattern(
|
||||
region,
|
||||
PatternCategory::PatternDefault,
|
||||
Type::Variable(*expr_var),
|
||||
PExpected::ForReason(
|
||||
PReason::OptionalField,
|
||||
pat_type.clone(),
|
||||
loc_expr.region,
|
||||
),
|
||||
));
|
||||
|
||||
state.vars.push(*expr_var);
|
||||
|
||||
let expr_expected = Expected::ForReason(
|
||||
Reason::RecordDefaultField(label.clone()),
|
||||
pat_type.clone(),
|
||||
loc_expr.region,
|
||||
);
|
||||
|
||||
state.constraints.push(Constraint::Eq(
|
||||
Type::Variable(*expr_var),
|
||||
expr_expected.clone(),
|
||||
Category::DefaultValue(label.clone()),
|
||||
region,
|
||||
));
|
||||
|
||||
state.vars.push(*expr_var);
|
||||
|
||||
let expr_con =
|
||||
constrain_expr(env, loc_expr.region, &loc_expr.value, expr_expected);
|
||||
state.constraints.push(expr_con);
|
||||
|
@ -253,7 +257,7 @@ pub fn constrain_pattern(
|
|||
}
|
||||
DestructType::Required => {
|
||||
// No extra constraints necessary.
|
||||
RecordField::Required(pat_type)
|
||||
RecordField::Demanded(pat_type)
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue