mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Register accessor closures when they are bound
Previously we only registered record accessor closures in anonymous contexts, where we assume they must already be specialized based on the surrounding contexts. This is not true in general since one might bind an accessor to a name. Closes #2567
This commit is contained in:
parent
d7c8c8de42
commit
3bff99b0a2
5 changed files with 154 additions and 26 deletions
|
@ -769,7 +769,8 @@ pub fn constrain_expr(
|
|||
function_var,
|
||||
field,
|
||||
record_var,
|
||||
closure_ext_var: closure_var,
|
||||
closure_var,
|
||||
closure_ext_var,
|
||||
ext_var,
|
||||
field_var,
|
||||
} => {
|
||||
|
@ -795,16 +796,24 @@ pub fn constrain_expr(
|
|||
|
||||
let lambda_set = Type::ClosureTag {
|
||||
name: *closure_name,
|
||||
ext: *closure_var,
|
||||
ext: *closure_ext_var,
|
||||
};
|
||||
|
||||
let closure_type = Type::Variable(*closure_var);
|
||||
|
||||
let function_type = Type::Function(
|
||||
vec![record_type],
|
||||
Box::new(lambda_set),
|
||||
Box::new(closure_type.clone()),
|
||||
Box::new(field_type),
|
||||
);
|
||||
|
||||
let cons = [
|
||||
constraints.equal_types(
|
||||
closure_type,
|
||||
NoExpectation(lambda_set),
|
||||
category.clone(),
|
||||
region,
|
||||
),
|
||||
constraints.equal_types(function_type.clone(), expected, category.clone(), region),
|
||||
constraints.equal_types(
|
||||
function_type,
|
||||
|
@ -816,7 +825,14 @@ pub fn constrain_expr(
|
|||
];
|
||||
|
||||
constraints.exists_many(
|
||||
[*record_var, *function_var, *closure_var, field_var, ext_var],
|
||||
[
|
||||
*record_var,
|
||||
*function_var,
|
||||
*closure_var,
|
||||
*closure_ext_var,
|
||||
field_var,
|
||||
ext_var,
|
||||
],
|
||||
cons,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue