fix: Discard not taken into account in backpassing
closes #890 Co-authored-by: Kasey White <kwhitemsg@gmail.com>
This commit is contained in:
parent
898ef74457
commit
4f8e900aac
|
@ -1300,7 +1300,7 @@ impl UntypedExpr {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lambda(
|
pub fn lambda(
|
||||||
names: Vec<(String, Span, Option<Annotation>)>,
|
names: Vec<(ArgName, Span, Option<Annotation>)>,
|
||||||
expressions: Vec<UntypedExpr>,
|
expressions: Vec<UntypedExpr>,
|
||||||
location: Span,
|
location: Span,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -1309,17 +1309,12 @@ impl UntypedExpr {
|
||||||
fn_style: FnStyle::Plain,
|
fn_style: FnStyle::Plain,
|
||||||
arguments: names
|
arguments: names
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(name, location, annotation)| Arg {
|
.map(|(arg_name, location, annotation)| Arg {
|
||||||
location,
|
location,
|
||||||
doc: None,
|
doc: None,
|
||||||
annotation,
|
annotation,
|
||||||
tipo: (),
|
tipo: (),
|
||||||
arg_name: ArgName::Named {
|
arg_name,
|
||||||
label: name.clone(),
|
|
||||||
name,
|
|
||||||
location,
|
|
||||||
is_validator_param: false,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
body: Self::Sequence {
|
body: Self::Sequence {
|
||||||
|
|
|
@ -2008,3 +2008,25 @@ fn correct_span_for_backpassing_args() {
|
||||||
matches!(&warnings[0], Warning::UnusedVariable { ref name, location } if name == "b" && location.start == 245 && location.end == 246)
|
matches!(&warnings[0], Warning::UnusedVariable { ref name, location } if name == "b" && location.start == 245 && location.end == 246)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn allow_discard_for_backpassing_args() {
|
||||||
|
let source_code = r#"
|
||||||
|
fn fold(list: List<a>, acc: b, f: fn(a, b) -> b) -> b {
|
||||||
|
when list is {
|
||||||
|
[] -> acc
|
||||||
|
[x, ..xs] -> fold(xs, f(x, acc), f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sum(list: List<Int>) -> Int {
|
||||||
|
let a, _b <- fold(list, 0)
|
||||||
|
|
||||||
|
a + 1
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let (warnings, _ast) = check(parse(source_code)).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(warnings.len(), 0);
|
||||||
|
}
|
||||||
|
|
|
@ -1768,14 +1768,41 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
// in front of the continuation sequence. This is because we do not support patterns in function argument
|
// in front of the continuation sequence. This is because we do not support patterns in function argument
|
||||||
// (which is perhaps something we should support?).
|
// (which is perhaps something we should support?).
|
||||||
match pattern {
|
match pattern {
|
||||||
Pattern::Var { name, location: _ } | Pattern::Discard { name, location: _ }
|
Pattern::Var {
|
||||||
if kind.is_let() =>
|
name,
|
||||||
{
|
location: var_location,
|
||||||
names.push((name.clone(), assignment_pattern_location, annotation));
|
} if kind.is_let() => {
|
||||||
|
let name = ArgName::Named {
|
||||||
|
label: name.clone(),
|
||||||
|
name,
|
||||||
|
location: var_location,
|
||||||
|
is_validator_param: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
names.push((name, assignment_pattern_location, annotation));
|
||||||
|
}
|
||||||
|
Pattern::Discard {
|
||||||
|
name,
|
||||||
|
location: var_location,
|
||||||
|
} if kind.is_let() => {
|
||||||
|
let name = ArgName::Discarded {
|
||||||
|
label: name.clone(),
|
||||||
|
name,
|
||||||
|
location: var_location,
|
||||||
|
};
|
||||||
|
|
||||||
|
names.push((name, assignment_pattern_location, annotation));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let name = format!("{}_{}", ast::BACKPASS_VARIABLE, index);
|
let name = format!("{}_{}", ast::BACKPASS_VARIABLE, index);
|
||||||
|
|
||||||
|
let arg_name = ArgName::Named {
|
||||||
|
label: name.clone(),
|
||||||
|
name: name.clone(),
|
||||||
|
location: pattern.location(),
|
||||||
|
is_validator_param: false,
|
||||||
|
};
|
||||||
|
|
||||||
continuation.insert(
|
continuation.insert(
|
||||||
0,
|
0,
|
||||||
UntypedExpr::Assignment {
|
UntypedExpr::Assignment {
|
||||||
|
@ -1799,7 +1826,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
names.push((name, assignment_pattern_location, annotation));
|
names.push((arg_name, assignment_pattern_location, annotation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue