fix problem with recursive definition constraint gen

This commit is contained in:
Folkert 2020-11-10 19:37:33 +01:00
parent b54c1a2194
commit 3aa6455795
7 changed files with 137 additions and 103 deletions

View file

@ -1006,10 +1006,10 @@ pub fn constrain_decls(home: ModuleId, decls: &[Declaration]) -> Constraint {
match decl {
Declaration::Declare(def) | Declaration::Builtin(def) => {
constraint = exists(Vec::new(), constrain_def(&env, def, constraint));
constraint = constrain_def(&env, def, constraint);
}
Declaration::DeclareRec(defs) => {
constraint = exists(Vec::new(), constrain_recursive_defs(&env, defs, constraint));
constraint = constrain_recursive_defs(&env, defs, constraint);
}
Declaration::InvalidCycle(_, _) => {
// invalid cycles give a canonicalization error. we skip them here.
@ -1440,32 +1440,31 @@ pub fn rec_defs_help(
},
def.loc_expr.region,
&def.loc_expr.value,
NoExpectation(expr_type.clone()),
annotation_expected.clone(),
);
// ensure expected type unifies with annotated type
rigid_info.constraints.push(Eq(
let storage_con = Eq(
expr_type,
annotation_expected.clone(),
Category::Storage,
def.loc_expr.region,
));
);
// TODO investigate if this let can be safely removed
let def_con = Let(Box::new(LetConstraint {
rigid_vars: Vec::new(),
flex_vars: Vec::new(), // empty because Roc function defs have no args
def_types: SendMap::default(), // empty because Roc function defs have no args
defs_constraint: True, // I think this is correct, once again because there are no args
defs_constraint: storage_con,
ret_constraint: expr_con,
}));
rigid_info.vars.extend(&new_rigids);
// because of how in Roc headers point to variables, we must include the pattern var here
rigid_info.vars.extend(pattern_state.vars);
rigid_info.constraints.push(Let(Box::new(LetConstraint {
rigid_vars: new_rigids,
flex_vars: Vec::new(), // no flex vars introduced
flex_vars: pattern_state.vars,
def_types: SendMap::default(), // no headers introduced (at this level)
defs_constraint: def_con,
ret_constraint: True,