diff --git a/schala-lang/src/parsing/combinator.rs b/schala-lang/src/parsing/combinator.rs index d9a2683..5e14998 100644 --- a/schala-lang/src/parsing/combinator.rs +++ b/schala-lang/src/parsing/combinator.rs @@ -293,32 +293,34 @@ fn func_signature(input: Span) -> ParseResult { "func-signature", preceded( kw("fn"), - cut(verify( - alt(( - map(normal_fn, |(name, params, type_anno)| Signature { - name: rc_string(name.fragment()), - operator: false, - params, - type_anno, - }), - map(operator_fn, |(op, params, type_anno)| Signature { - name: rc_string(op.sigil()), - operator: true, - params, - type_anno, - }), - )), - |sig| sig.params.len() < 256, - )), + cut(alt(( + map(normal_fn, |(name, params, type_anno)| Signature { + name: rc_string(name.fragment()), + operator: false, + params, + type_anno, + }), + map(operator_fn, |(op, params, type_anno)| Signature { + name: rc_string(op.sigil()), + operator: true, + params, + type_anno, + }), + ))), ), )(input) } fn formal_params(input: Span) -> ParseResult> { - delimited(tok(char('(')), separated_list0(tok(char(',')), formal_param), tok(char(')')))(input) + context( + "formal-params", + verify( + delimited(tok(char('(')), separated_list0(tok(char(',')), formal_param), tok(char(')'))), + |params: &Vec<_>| params.len() < 256, + ), + )(input) } -//TODO support 256-limit fn formal_param(input: Span) -> ParseResult { map( tuple((identifier, opt(type_anno), opt(preceded(tok(char('=')), expression)))), diff --git a/schala-lang/src/parsing/test.rs b/schala-lang/src/parsing/test.rs index 9d4e6cb..21079f3 100644 --- a/schala-lang/src/parsing/test.rs +++ b/schala-lang/src/parsing/test.rs @@ -886,6 +886,14 @@ fn max_function_params() { //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); + + let mut buf = r#"\("#.to_string(); + for n in 0..255 { + write!(buf, "a{}, ", n).unwrap(); + } + write!(buf, " a256").unwrap(); + write!(buf, ") {{ return 10 }}").unwrap(); + assert_fail!(&buf); } #[test]