Skip to content

Commit

Permalink
Address review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocavalieri committed Feb 10, 2025
1 parent 5cc8f28 commit 792560e
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions compiler-core/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4142,8 +4142,11 @@ pub fn make_call(
label,
} => {
num_holes += 1;
hole_location = Some(arg_location);
if num_holes > 1 {
return parse_error(ParseErrorType::TooManyArgHoles, SrcSpan { start, end });
}

hole_location = Some(arg_location);
if name != "_" {
return parse_error(
ParseErrorType::UnexpectedToken {
Expand All @@ -4167,36 +4170,36 @@ pub fn make_call(
}
})
.collect::<Result<_, _>>()?;

let call = UntypedExpr::Call {
location: SrcSpan { start, end },
fun: Box::new(fun),
arguments: args,
};
match num_holes {

match hole_location {
// A normal call
0 => Ok(call),
None => Ok(call),

// An anon function using the capture syntax run(_, 1, 2)
1 => Ok(UntypedExpr::Fn {
Some(hole_location) => Ok(UntypedExpr::Fn {
location: call.location(),
end_of_head_byte_index: call.location().end,
kind: FunctionLiteralKind::Capture {
hole: hole_location.expect("At least a capture hole"),
hole: hole_location,
},
arguments: vec![Arg {
location: hole_location.expect("At least a capture hole"),
location: hole_location,
annotation: None,
names: ArgNames::Named {
name: CAPTURE_VARIABLE.into(),
location: hole_location.expect("At least a capture hole"),
location: hole_location,
},
type_: (),
}],
body: vec1![Statement::Expression(call)],
return_annotation: None,
}),

_ => parse_error(ParseErrorType::TooManyArgHoles, SrcSpan { start, end }),
}
}

Expand Down

0 comments on commit 792560e

Please sign in to comment.