mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
add Accessor to uniqueness typecheck
This commit is contained in:
parent
99b3f35ff7
commit
d377d8ab8b
2 changed files with 32 additions and 2 deletions
|
@ -6,6 +6,7 @@ use crate::can::procedure::{Procedure, References};
|
|||
use crate::can::symbol::Symbol;
|
||||
use crate::collections::{ImMap, SendMap};
|
||||
// use crate::constrain::{self, exists};
|
||||
use crate::can::ident::Lowercase;
|
||||
use crate::can::pattern;
|
||||
use crate::ident::Ident;
|
||||
use crate::region::{Located, Region};
|
||||
|
@ -518,6 +519,32 @@ pub fn canonicalize_expr(
|
|||
|
||||
(output, And(constraints))
|
||||
}
|
||||
|
||||
Accessor(name) => {
|
||||
let ext_var = var_store.fresh();
|
||||
let ext_type = Variable(ext_var);
|
||||
|
||||
let field_var = var_store.fresh();
|
||||
let field_type = Variable(field_var);
|
||||
|
||||
let mut field_types = SendMap::default();
|
||||
let field_name: Lowercase = name.clone().into();
|
||||
field_types.insert(field_name, field_type.clone());
|
||||
let record_type =
|
||||
constrain::lift(var_store, Type::Record(field_types, Box::new(ext_type)));
|
||||
|
||||
(
|
||||
Output::default(),
|
||||
exists(
|
||||
vec![field_var, ext_var],
|
||||
Eq(
|
||||
Type::Function(vec![record_type], Box::new(field_type)),
|
||||
expected,
|
||||
region,
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
_ => panic!("{:?}", expr),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -867,6 +867,9 @@ mod test_infer_uniq {
|
|||
"Attr.Attr * Int",
|
||||
);
|
||||
}
|
||||
/*
|
||||
*/
|
||||
|
||||
#[test]
|
||||
fn accessor_function() {
|
||||
infer_eq(".foo", "Attr.Attr * { foo : a }* -> a");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue