mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Clippy vs McGregor 2047
This commit is contained in:
parent
935a484c71
commit
87245def0a
2 changed files with 47 additions and 43 deletions
|
@ -683,19 +683,24 @@ pub fn constrain_expr<'a>(
|
||||||
// when_branch.patterns.iter(env.pool).map(|v| &v.region),
|
// when_branch.patterns.iter(env.pool).map(|v| &v.region),
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
let patten_expected = |sub_pattern| {
|
||||||
|
PExpected::ForReason(
|
||||||
|
PReason::WhenMatch {
|
||||||
|
index: HumanIndex::zero_based(index),
|
||||||
|
sub_pattern,
|
||||||
|
},
|
||||||
|
cond_type.shallow_clone(),
|
||||||
|
pattern_region,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
let branch_con = constrain_when_branch(
|
let branch_con = constrain_when_branch(
|
||||||
arena,
|
arena,
|
||||||
env,
|
env,
|
||||||
// TODO: when_branch.value.region,
|
// TODO: when_branch.value.region,
|
||||||
region,
|
region,
|
||||||
when_branch,
|
when_branch,
|
||||||
PExpected::ForReason(
|
patten_expected,
|
||||||
PReason::WhenMatch {
|
|
||||||
index: HumanIndex::zero_based(index),
|
|
||||||
},
|
|
||||||
cond_type.shallow_clone(),
|
|
||||||
pattern_region,
|
|
||||||
),
|
|
||||||
Expected::FromAnnotation(
|
Expected::FromAnnotation(
|
||||||
name.clone(),
|
name.clone(),
|
||||||
*arity,
|
*arity,
|
||||||
|
@ -726,18 +731,23 @@ pub fn constrain_expr<'a>(
|
||||||
// let pattern_region =
|
// let pattern_region =
|
||||||
// Region::across_all(when_branch.patterns.iter().map(|v| &v.region));
|
// Region::across_all(when_branch.patterns.iter().map(|v| &v.region));
|
||||||
|
|
||||||
|
let patten_expected = |sub_pattern| {
|
||||||
|
PExpected::ForReason(
|
||||||
|
PReason::WhenMatch {
|
||||||
|
index: HumanIndex::zero_based(index),
|
||||||
|
sub_pattern,
|
||||||
|
},
|
||||||
|
cond_type.shallow_clone(),
|
||||||
|
pattern_region,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
let branch_con = constrain_when_branch(
|
let branch_con = constrain_when_branch(
|
||||||
arena,
|
arena,
|
||||||
env,
|
env,
|
||||||
region,
|
region,
|
||||||
when_branch,
|
when_branch,
|
||||||
PExpected::ForReason(
|
patten_expected,
|
||||||
PReason::WhenMatch {
|
|
||||||
index: HumanIndex::zero_based(index),
|
|
||||||
},
|
|
||||||
cond_type.shallow_clone(),
|
|
||||||
pattern_region,
|
|
||||||
),
|
|
||||||
Expected::ForReason(
|
Expected::ForReason(
|
||||||
Reason::WhenBranch {
|
Reason::WhenBranch {
|
||||||
index: HumanIndex::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
|
@ -1296,7 +1306,7 @@ fn constrain_when_branch<'a>(
|
||||||
env: &mut Env,
|
env: &mut Env,
|
||||||
region: Region,
|
region: Region,
|
||||||
when_branch: &WhenBranch,
|
when_branch: &WhenBranch,
|
||||||
pattern_expected: PExpected<Type2>,
|
pattern_expected: impl Fn(HumanIndex) -> PExpected<Type2>,
|
||||||
expr_expected: Expected<Type2>,
|
expr_expected: Expected<Type2>,
|
||||||
) -> Constraint<'a> {
|
) -> Constraint<'a> {
|
||||||
let when_expr = env.pool.get(when_branch.body);
|
let when_expr = env.pool.get(when_branch.body);
|
||||||
|
@ -1311,16 +1321,18 @@ fn constrain_when_branch<'a>(
|
||||||
|
|
||||||
// TODO investigate for error messages, is it better to unify all branches with a variable,
|
// TODO investigate for error messages, is it better to unify all branches with a variable,
|
||||||
// then unify that variable with the expectation?
|
// then unify that variable with the expectation?
|
||||||
for pattern_id in when_branch.patterns.iter_node_ids() {
|
for (sub_pattern, pattern_id) in when_branch.patterns.iter_node_ids().enumerate() {
|
||||||
let pattern = env.pool.get(pattern_id);
|
let pattern = env.pool.get(pattern_id);
|
||||||
|
|
||||||
|
let pattern_expected = pattern_expected(HumanIndex::zero_based(sub_pattern));
|
||||||
|
|
||||||
constrain_pattern(
|
constrain_pattern(
|
||||||
arena,
|
arena,
|
||||||
env,
|
env,
|
||||||
pattern,
|
pattern,
|
||||||
// loc_pattern.region,
|
// loc_pattern.region,
|
||||||
region,
|
region,
|
||||||
pattern_expected.shallow_clone(),
|
pattern_expected,
|
||||||
&mut state,
|
&mut state,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1188,34 +1188,26 @@ fn solve(
|
||||||
use {Content::*, FlatType::*};
|
use {Content::*, FlatType::*};
|
||||||
|
|
||||||
let mut desc = subs.get(var);
|
let mut desc = subs.get(var);
|
||||||
match desc.content {
|
if let Structure(TagUnion(tags, ext)) = desc.content {
|
||||||
Structure(TagUnion(tags, ext)) => {
|
if let Structure(EmptyTagUnion) = subs.get_content_without_compacting(ext) {
|
||||||
match subs.get_content_without_compacting(ext) {
|
let new_ext = subs.fresh_unnamed_flex_var();
|
||||||
Structure(FlatType::EmptyTagUnion) => {
|
subs.set_rank(new_ext, desc.rank);
|
||||||
let new_ext = subs.fresh_unnamed_flex_var();
|
let new_union = Structure(TagUnion(tags, new_ext));
|
||||||
subs.set_rank(new_ext, desc.rank);
|
desc.content = new_union;
|
||||||
let new_union = Structure(TagUnion(tags, new_ext));
|
subs.set(var, desc);
|
||||||
desc.content = new_union;
|
}
|
||||||
subs.set(var, desc);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Also open up all nested tag unions.
|
// Also open up all nested tag unions.
|
||||||
let all_vars = tags.variables().into_iter();
|
let all_vars = tags.variables().into_iter();
|
||||||
stack.extend(
|
stack.extend(all_vars.flat_map(|slice| subs[slice]).map(|var| subs[var]));
|
||||||
all_vars.flat_map(|slice| subs[slice]).map(|var| subs[var]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
// Today, an "open" constraint doesn't affect any types
|
|
||||||
// other than tag unions. Recursive tag unions are constructed
|
|
||||||
// at a later time (during occurs checks after tag unions are
|
|
||||||
// resolved), so that's not handled here either.
|
|
||||||
// NB: Handle record types here if we add presence constraints
|
|
||||||
// to their type inference as well.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Today, an "open" constraint doesn't affect any types
|
||||||
|
// other than tag unions. Recursive tag unions are constructed
|
||||||
|
// at a later time (during occurs checks after tag unions are
|
||||||
|
// resolved), so that's not handled here either.
|
||||||
|
// NB: Handle record types here if we add presence constraints
|
||||||
|
// to their type inference as well.
|
||||||
}
|
}
|
||||||
|
|
||||||
state
|
state
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue