From 75d18eb8ba88fe2912562b19eeecbd379efd05cb Mon Sep 17 00:00:00 2001 From: Folkert Date: Thu, 12 Nov 2020 15:31:25 +0100 Subject: [PATCH] no more rigid mistakes? --- compiler/constrain/src/expr.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 3a5328dd4a..6c63a4dc4e 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -1220,11 +1220,17 @@ fn constrain_def(env: &Env, def: &Def, body_con: Constraint) -> Constraint { ret_constraint, })), // "the closure's type is equal to expected type" - Eq(fn_type.clone(), expected, Category::Lambda, region), + Eq(fn_type.clone(), expected.clone(), Category::Lambda, region), // "fn_var is equal to the closure's type" - fn_var is used in code gen Eq( Type::Variable(*fn_var), - NoExpectation(fn_type), + NoExpectation(Type::Variable(expr_var)), + Category::Storage(std::file!(), std::line!()), + region, + ), + Eq( + Type::Variable(expr_var), + expected, Category::Storage(std::file!(), std::line!()), region, ), @@ -1378,6 +1384,8 @@ pub fn rec_defs_help( let mut def_pattern_state = constrain_def_pattern(env, &def.loc_pattern, expr_type.clone()); + def_pattern_state.vars.push(expr_var); + let mut new_rigids = Vec::new(); match &def.annotation { None => { @@ -1388,8 +1396,6 @@ pub fn rec_defs_help( NoExpectation(expr_type), ); - def_pattern_state.vars.push(expr_var); - // TODO investigate if this let can be safely removed let def_con = Let(Box::new(LetConstraint { rigid_vars: Vec::new(), @@ -1571,7 +1577,7 @@ pub fn rec_defs_help( defs_constraint: And(state.constraints), ret_constraint: expr_con, })), - Eq(fn_type.clone(), expected, Category::Lambda, region), + Eq(fn_type.clone(), expected.clone(), Category::Lambda, region), // "fn_var is equal to the closure's type" - fn_var is used in code gen Eq( Type::Variable(*fn_var), @@ -1579,6 +1585,12 @@ pub fn rec_defs_help( Category::Storage(std::file!(), std::line!()), region, ), + Eq( + Type::Variable(expr_var), + expected, + Category::Storage(std::file!(), std::line!()), + region, + ), closure_constraint, ]), );