mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
fix record accessors
This commit is contained in:
parent
80423bac76
commit
a055fa3626
3 changed files with 30 additions and 17 deletions
|
@ -135,9 +135,12 @@ pub enum Expr {
|
|||
},
|
||||
/// field accessor as a function, e.g. (.foo) expr
|
||||
Accessor {
|
||||
/// accessors are desugared to closures; they need to have a name
|
||||
/// so the closure can have a correct lambda set
|
||||
name: Symbol,
|
||||
function_var: Variable,
|
||||
record_var: Variable,
|
||||
closure_var: Variable,
|
||||
closure_ext_var: Variable,
|
||||
ext_var: Variable,
|
||||
field_var: Variable,
|
||||
field: Lowercase,
|
||||
|
@ -613,10 +616,11 @@ pub fn canonicalize_expr<'a>(
|
|||
}
|
||||
ast::Expr::AccessorFunction(field) => (
|
||||
Accessor {
|
||||
name: env.gen_unique_symbol(),
|
||||
function_var: var_store.fresh(),
|
||||
record_var: var_store.fresh(),
|
||||
ext_var: var_store.fresh(),
|
||||
closure_var: var_store.fresh(),
|
||||
closure_ext_var: var_store.fresh(),
|
||||
field_var: var_store.fresh(),
|
||||
field: (*field).into(),
|
||||
},
|
||||
|
|
|
@ -10,7 +10,7 @@ use roc_can::expr::Expr::{self, *};
|
|||
use roc_can::expr::{Field, WhenBranch};
|
||||
use roc_can::pattern::Pattern;
|
||||
use roc_collections::all::{ImMap, Index, SendMap};
|
||||
use roc_module::ident::Lowercase;
|
||||
use roc_module::ident::{Lowercase, TagName};
|
||||
use roc_module::symbol::{ModuleId, Symbol};
|
||||
use roc_region::all::{Located, Region};
|
||||
use roc_types::subs::Variable;
|
||||
|
@ -712,10 +712,11 @@ pub fn constrain_expr(
|
|||
)
|
||||
}
|
||||
Accessor {
|
||||
name: closure_name,
|
||||
function_var,
|
||||
field,
|
||||
record_var,
|
||||
closure_var,
|
||||
closure_ext_var: closure_var,
|
||||
ext_var,
|
||||
field_var,
|
||||
} => {
|
||||
|
@ -739,9 +740,15 @@ pub fn constrain_expr(
|
|||
region,
|
||||
);
|
||||
|
||||
let ext = Type::Variable(*closure_var);
|
||||
let lambda_set = Type::TagUnion(
|
||||
vec![(TagName::Closure(*closure_name), vec![])],
|
||||
Box::new(ext),
|
||||
);
|
||||
|
||||
let function_type = Type::Function(
|
||||
vec![record_type],
|
||||
Box::new(Type::Variable(*closure_var)),
|
||||
Box::new(lambda_set),
|
||||
Box::new(field_type),
|
||||
);
|
||||
|
||||
|
|
|
@ -3652,9 +3652,10 @@ pub fn with_hole<'a>(
|
|||
}
|
||||
|
||||
Accessor {
|
||||
name,
|
||||
function_var,
|
||||
record_var,
|
||||
closure_var: _,
|
||||
closure_ext_var: _,
|
||||
ext_var,
|
||||
field_var,
|
||||
field,
|
||||
|
@ -3677,8 +3678,6 @@ pub fn with_hole<'a>(
|
|||
|
||||
let loc_body = Located::at_zero(body);
|
||||
|
||||
let name = env.unique_symbol();
|
||||
|
||||
let arguments = vec![(
|
||||
record_var,
|
||||
Located::at_zero(roc_can::pattern::Pattern::Identifier(record_symbol)),
|
||||
|
@ -3694,15 +3693,18 @@ pub fn with_hole<'a>(
|
|||
field_var,
|
||||
layout_cache,
|
||||
) {
|
||||
Ok(layout) => {
|
||||
todo!()
|
||||
// TODO should the let have layout Pointer?
|
||||
// Stmt::Let(
|
||||
// assigned,
|
||||
// call_by_pointer(env, procs, name, layout),
|
||||
// layout,
|
||||
// hole,
|
||||
// )
|
||||
Ok(_) => {
|
||||
let full_layout = return_on_layout_error!(
|
||||
env,
|
||||
layout_cache.from_var(env.arena, function_var, env.subs)
|
||||
);
|
||||
|
||||
match full_layout {
|
||||
Layout::Closure(_, lambda_set, _) => {
|
||||
construct_closure_data(env, lambda_set, name, &[], assigned, hole)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
Err(_error) => Stmt::RuntimeError(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue