Merge branch 'trunk' into ct/multi-line-if

This commit is contained in:
Chadtech 2019-12-21 13:50:54 -05:00 committed by GitHub
commit c8eae2b160
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 2 deletions

View file

@ -60,6 +60,8 @@ pub enum Expr {
/// Look up exactly one field on a record, e.g. (expr).foo.
Access(Box<Located<Expr>>, Box<str>),
/// field accessor as a function, e.g. (.foo) expr
Accessor(Box<str>),
Tag(Box<str>, Vec<Expr>),
@ -714,8 +716,33 @@ pub fn canonicalize_expr(
constraint,
)
}
ast::Expr::AccessorFunction(_)
| ast::Expr::If(_)
ast::Expr::AccessorFunction(field) => {
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 = (*field).into();
field_types.insert(field_name.clone(), field_type.clone());
let record_type = Type::Record(field_types, Box::new(ext_type));
(
Accessor(field_name.into()),
Output::default(),
exists(
vec![field_var, ext_var],
Eq(
Type::Function(vec![record_type], Box::new(field_type)),
expected,
region,
),
),
)
}
ast::Expr::If(_)
| ast::Expr::GlobalTag(_)
| ast::Expr::PrivateTag(_)
| ast::Expr::MalformedIdent(_)

View file

@ -869,4 +869,9 @@ mod test_infer {
"custom -> custom",
);
}
#[test]
fn accessor_function() {
infer_eq(".foo", "{ foo : a }* -> a");
}
}