mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Generalize return vars
This commit is contained in:
parent
8b9f122047
commit
febe95c228
2 changed files with 23 additions and 2 deletions
|
@ -1438,14 +1438,16 @@ pub fn constrain_expr(
|
||||||
return_value.region,
|
return_value.region,
|
||||||
));
|
));
|
||||||
|
|
||||||
constrain_expr(
|
let return_con = constrain_expr(
|
||||||
types,
|
types,
|
||||||
constraints,
|
constraints,
|
||||||
env,
|
env,
|
||||||
return_value.region,
|
return_value.region,
|
||||||
&return_value.value,
|
&return_value.value,
|
||||||
expected_return_value,
|
expected_return_value,
|
||||||
)
|
);
|
||||||
|
|
||||||
|
constraints.exists([*return_var], return_con)
|
||||||
}
|
}
|
||||||
Tag {
|
Tag {
|
||||||
tag_union_var: variant_var,
|
tag_union_var: variant_var,
|
||||||
|
|
|
@ -14726,6 +14726,25 @@ All branches in an `if` must have the same type!
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test_report!(
|
||||||
|
function_with_early_return_generalizes,
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
parseItemsWith = \parser ->
|
||||||
|
when List.mapTry ["123", "456"] parser is
|
||||||
|
Ok ok -> Ok ok
|
||||||
|
Err err ->
|
||||||
|
return Err err
|
||||||
|
|
||||||
|
u64Nums = parseItemsWith Str.toU64
|
||||||
|
u8Nums = parseItemsWith Str.toU8
|
||||||
|
|
||||||
|
"$(Inspect.toStr u64Nums) $(Inspect.toStr u8Nums)"
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
@"" // no errors
|
||||||
|
);
|
||||||
|
|
||||||
test_report!(
|
test_report!(
|
||||||
leftover_statement,
|
leftover_statement,
|
||||||
indoc!(
|
indoc!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue