Fix function argument limit

This commit is contained in:
Greg Shuflin 2021-11-21 03:00:19 -08:00
parent bf55e6e82a
commit 032fe5fed9
2 changed files with 22 additions and 18 deletions

View File

@ -154,13 +154,13 @@ fn block_template<'a, O, O2>(
) -> impl FnMut(Span<'a>) -> IResult<Span<'a>, Vec<O>, VerboseError<Span<'a>>> {
delimited(
pair(tok(char('{')), many0(statement_delimiter)),
separated_list0(delimiter, input_parser),
cut(separated_list0(delimiter, input_parser)),
pair(many0(statement_delimiter), tok(char('}'))),
)
}
pub fn block(input: Span) -> ParseResult<Block> {
map(block_template(many1(statement_delimiter), statement), |items| items.into())(input)
context("block", map(block_template(many1(statement_delimiter), statement), |items| items.into()))(input)
}
fn statement(input: Span) -> ParseResult<Statement> {
@ -293,7 +293,8 @@ fn func_signature(input: Span) -> ParseResult<Signature> {
"func-signature",
preceded(
kw("fn"),
cut(alt((
cut(verify(
alt((
map(normal_fn, |(name, params, type_anno)| Signature {
name: rc_string(name.fragment()),
operator: false,
@ -306,7 +307,9 @@ fn func_signature(input: Span) -> ParseResult<Signature> {
params,
type_anno,
}),
))),
)),
|sig| sig.params.len() < 256,
)),
),
)(input)
}

View File

@ -878,12 +878,13 @@ fn custom_operator() {
#[test]
fn max_function_params() {
let mut buf = "fn longfunc(".to_string();
for n in 0..256 {
for n in 0..255 {
write!(buf, "a{}, ", n).unwrap();
}
write!(buf, " a256").unwrap();
write!(buf, ") {{ return 20 }}").unwrap();
//assert_fail!(&buf, "A function cannot have more than 255 arguments");
//TODO need to create a good, custom error message for this case
//assert_fail!(&buf, "A function cannot have more than 255 arguments");
assert_fail!(&buf);
}