mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +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
|
/// field accessor as a function, e.g. (.foo) expr
|
||||||
Accessor {
|
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,
|
function_var: Variable,
|
||||||
record_var: Variable,
|
record_var: Variable,
|
||||||
closure_var: Variable,
|
closure_ext_var: Variable,
|
||||||
ext_var: Variable,
|
ext_var: Variable,
|
||||||
field_var: Variable,
|
field_var: Variable,
|
||||||
field: Lowercase,
|
field: Lowercase,
|
||||||
|
@ -613,10 +616,11 @@ pub fn canonicalize_expr<'a>(
|
||||||
}
|
}
|
||||||
ast::Expr::AccessorFunction(field) => (
|
ast::Expr::AccessorFunction(field) => (
|
||||||
Accessor {
|
Accessor {
|
||||||
|
name: env.gen_unique_symbol(),
|
||||||
function_var: var_store.fresh(),
|
function_var: var_store.fresh(),
|
||||||
record_var: var_store.fresh(),
|
record_var: var_store.fresh(),
|
||||||
ext_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_var: var_store.fresh(),
|
||||||
field: (*field).into(),
|
field: (*field).into(),
|
||||||
},
|
},
|
||||||
|
|
|
@ -10,7 +10,7 @@ use roc_can::expr::Expr::{self, *};
|
||||||
use roc_can::expr::{Field, WhenBranch};
|
use roc_can::expr::{Field, WhenBranch};
|
||||||
use roc_can::pattern::Pattern;
|
use roc_can::pattern::Pattern;
|
||||||
use roc_collections::all::{ImMap, Index, SendMap};
|
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_module::symbol::{ModuleId, Symbol};
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Located, Region};
|
||||||
use roc_types::subs::Variable;
|
use roc_types::subs::Variable;
|
||||||
|
@ -712,10 +712,11 @@ pub fn constrain_expr(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Accessor {
|
Accessor {
|
||||||
|
name: closure_name,
|
||||||
function_var,
|
function_var,
|
||||||
field,
|
field,
|
||||||
record_var,
|
record_var,
|
||||||
closure_var,
|
closure_ext_var: closure_var,
|
||||||
ext_var,
|
ext_var,
|
||||||
field_var,
|
field_var,
|
||||||
} => {
|
} => {
|
||||||
|
@ -739,9 +740,15 @@ pub fn constrain_expr(
|
||||||
region,
|
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(
|
let function_type = Type::Function(
|
||||||
vec![record_type],
|
vec![record_type],
|
||||||
Box::new(Type::Variable(*closure_var)),
|
Box::new(lambda_set),
|
||||||
Box::new(field_type),
|
Box::new(field_type),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -3652,9 +3652,10 @@ pub fn with_hole<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
Accessor {
|
Accessor {
|
||||||
|
name,
|
||||||
function_var,
|
function_var,
|
||||||
record_var,
|
record_var,
|
||||||
closure_var: _,
|
closure_ext_var: _,
|
||||||
ext_var,
|
ext_var,
|
||||||
field_var,
|
field_var,
|
||||||
field,
|
field,
|
||||||
|
@ -3677,8 +3678,6 @@ pub fn with_hole<'a>(
|
||||||
|
|
||||||
let loc_body = Located::at_zero(body);
|
let loc_body = Located::at_zero(body);
|
||||||
|
|
||||||
let name = env.unique_symbol();
|
|
||||||
|
|
||||||
let arguments = vec![(
|
let arguments = vec![(
|
||||||
record_var,
|
record_var,
|
||||||
Located::at_zero(roc_can::pattern::Pattern::Identifier(record_symbol)),
|
Located::at_zero(roc_can::pattern::Pattern::Identifier(record_symbol)),
|
||||||
|
@ -3694,15 +3693,18 @@ pub fn with_hole<'a>(
|
||||||
field_var,
|
field_var,
|
||||||
layout_cache,
|
layout_cache,
|
||||||
) {
|
) {
|
||||||
Ok(layout) => {
|
Ok(_) => {
|
||||||
todo!()
|
let full_layout = return_on_layout_error!(
|
||||||
// TODO should the let have layout Pointer?
|
env,
|
||||||
// Stmt::Let(
|
layout_cache.from_var(env.arena, function_var, env.subs)
|
||||||
// assigned,
|
);
|
||||||
// call_by_pointer(env, procs, name, layout),
|
|
||||||
// layout,
|
match full_layout {
|
||||||
// hole,
|
Layout::Closure(_, lambda_set, _) => {
|
||||||
// )
|
construct_closure_data(env, lambda_set, name, &[], assigned, hole)
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(_error) => Stmt::RuntimeError(
|
Err(_error) => Stmt::RuntimeError(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue