mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
accept a newline and body when patterns are different
This commit is contained in:
parent
1b4c5cac25
commit
58dfeba043
3 changed files with 32 additions and 1 deletions
|
@ -151,7 +151,7 @@ pub fn canonicalize_defs<'a>(
|
|||
match iter.peek() {
|
||||
Some(Located {
|
||||
value: Body(body_pattern, body_expr),
|
||||
..
|
||||
region: body_region,
|
||||
}) => {
|
||||
if pattern.value.equivalent(&body_pattern.value) {
|
||||
iter.next();
|
||||
|
@ -165,6 +165,10 @@ pub fn canonicalize_defs<'a>(
|
|||
&mut scope,
|
||||
pattern_type,
|
||||
)
|
||||
} else if loc_def.region.lines_between(body_region) > 1 {
|
||||
// there is a line of whitespace between the annotation and the body
|
||||
// treat annotation and body separately
|
||||
to_pending_def(env, var_store, &loc_def.value, &mut scope, pattern_type)
|
||||
} else {
|
||||
// the pattern of the annotation does not match the pattern of the body directly below it
|
||||
env.problems.push(Problem::SignatureDefMismatch {
|
||||
|
|
|
@ -78,6 +78,17 @@ impl Region {
|
|||
Self::zero()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lines_between(&self, other: &Region) -> u32 {
|
||||
if self.end_line <= other.start_line {
|
||||
other.start_line - self.end_line
|
||||
} else if self.start_line >= other.end_line {
|
||||
self.start_line - other.end_line
|
||||
} else {
|
||||
// intersection
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -2839,6 +2839,22 @@ mod test_reporting {
|
|||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn annotation_newline_body_is_fine() {
|
||||
report_problem_as(
|
||||
indoc!(
|
||||
r#"
|
||||
bar : Int
|
||||
|
||||
foo = \x -> x
|
||||
|
||||
foo bar
|
||||
"#
|
||||
),
|
||||
indoc!(""),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_alias_rigid_var_pattern() {
|
||||
report_problem_as(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue