mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 15:03:46 +00:00
Contrain module params pattern
This commit is contained in:
parent
674adf1fad
commit
8f69e75a95
2 changed files with 55 additions and 2 deletions
|
@ -1,11 +1,14 @@
|
|||
use crate::expr::{constrain_def_make_constraint, constrain_def_pattern, Env};
|
||||
use crate::pattern::{constrain_pattern, PatternState};
|
||||
use roc_can::abilities::{PendingAbilitiesStore, PendingMemberType};
|
||||
use roc_can::constraint::{Constraint, Constraints, Generalizable};
|
||||
use roc_can::expected::Expected;
|
||||
use roc_can::expr::Declarations;
|
||||
use roc_can::expected::{Expected, PExpected};
|
||||
use roc_can::expr::{AnnotatedMark, Declarations};
|
||||
use roc_can::pattern::Pattern;
|
||||
use roc_collections::MutMap;
|
||||
use roc_module::symbol::{ModuleId, Symbol};
|
||||
use roc_region::all::{Loc, Region};
|
||||
use roc_types::subs::Variable;
|
||||
use roc_types::types::{AnnotationSource, Category, Type, Types};
|
||||
|
||||
pub fn constrain_module(
|
||||
|
@ -14,9 +17,18 @@ pub fn constrain_module(
|
|||
symbols_from_requires: Vec<(Loc<Symbol>, Loc<Type>)>,
|
||||
abilities_store: &PendingAbilitiesStore,
|
||||
declarations: &Declarations,
|
||||
params_pattern: &Option<(Variable, AnnotatedMark, Loc<Pattern>)>,
|
||||
home: ModuleId,
|
||||
) -> Constraint {
|
||||
let constraint = crate::expr::constrain_decls(types, constraints, home, declarations);
|
||||
|
||||
let constraint = match params_pattern {
|
||||
Some(params_pattern) => {
|
||||
constrain_params(types, constraints, home, constraint, params_pattern)
|
||||
}
|
||||
None => constraint,
|
||||
};
|
||||
|
||||
let constraint = constrain_symbols_from_requires(
|
||||
types,
|
||||
constraints,
|
||||
|
@ -33,6 +45,46 @@ pub fn constrain_module(
|
|||
constraint
|
||||
}
|
||||
|
||||
fn constrain_params(
|
||||
types: &mut Types,
|
||||
constraints: &mut Constraints,
|
||||
home: ModuleId,
|
||||
constraint: Constraint,
|
||||
(pattern_var, _, loc_pattern): &(Variable, AnnotatedMark, Loc<Pattern>),
|
||||
) -> Constraint {
|
||||
let mut env = Env {
|
||||
home,
|
||||
rigids: MutMap::default(),
|
||||
resolutions_to_make: vec![],
|
||||
};
|
||||
|
||||
let index = constraints.push_variable(*pattern_var);
|
||||
let expected_params = constraints.push_pat_expected_type(PExpected::NoExpectation(index));
|
||||
|
||||
let mut state = PatternState::default();
|
||||
|
||||
constrain_pattern(
|
||||
types,
|
||||
constraints,
|
||||
&mut env,
|
||||
&loc_pattern.value,
|
||||
loc_pattern.region,
|
||||
expected_params,
|
||||
&mut state,
|
||||
);
|
||||
|
||||
let pattern_constraints = constraints.and_constraint(state.constraints);
|
||||
|
||||
constraints.let_constraint(
|
||||
[],
|
||||
state.vars,
|
||||
state.headers,
|
||||
pattern_constraints,
|
||||
constraint,
|
||||
Generalizable(true),
|
||||
)
|
||||
}
|
||||
|
||||
fn constrain_symbols_from_requires(
|
||||
types: &mut Types,
|
||||
constraints: &mut Constraints,
|
||||
|
|
|
@ -5065,6 +5065,7 @@ fn canonicalize_and_constrain<'a>(
|
|||
module_output.symbols_from_requires,
|
||||
&module_output.scope.abilities_store,
|
||||
&module_output.declarations,
|
||||
&module_output.params_pattern,
|
||||
module_id,
|
||||
)
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue