Disallow functions with more than 255 arguments
This commit is contained in:
parent
45c72f97a2
commit
8336211a4b
@ -562,7 +562,13 @@ impl Parser {
|
|||||||
|
|
||||||
#[recursive_descent_method]
|
#[recursive_descent_method]
|
||||||
fn formal_param_list(&mut self) -> ParseResult<Vec<FormalParam>> {
|
fn formal_param_list(&mut self) -> ParseResult<Vec<FormalParam>> {
|
||||||
Ok(delimited!(self, LParen, formal_param, Comma, RParen))
|
let tok = self.token_handler.peek();
|
||||||
|
let list = delimited!(self, LParen, formal_param, Comma, RParen);
|
||||||
|
if list.len() > 255 {
|
||||||
|
ParseError::new_with_token("A function cannot have more than 255 arguments", tok.clone())
|
||||||
|
} else {
|
||||||
|
Ok(list)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[recursive_descent_method]
|
#[recursive_descent_method]
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#![allow(clippy::upper_case_acronyms)]
|
#![allow(clippy::upper_case_acronyms)]
|
||||||
#![allow(clippy::vec_init_then_push)]
|
#![allow(clippy::vec_init_then_push)]
|
||||||
//use test_case::test_case;
|
//use test_case::test_case;
|
||||||
use std::rc::Rc;
|
use std::{fmt::Write, rc::Rc};
|
||||||
|
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
@ -788,6 +788,16 @@ fn functions() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn max_function_params() {
|
||||||
|
let mut buf = "fn longfunc(".to_string();
|
||||||
|
for n in 0..256 {
|
||||||
|
write!(buf, "a{}, ", n).unwrap();
|
||||||
|
}
|
||||||
|
write!(buf, ") {{ return 20 }}").unwrap();
|
||||||
|
assert_fail!(&buf, "A function cannot have more than 255 arguments");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn functions_with_different_whitespace() {
|
fn functions_with_different_whitespace() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
@ -9,7 +9,7 @@ use crate::{
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum NameType {
|
enum NameType {
|
||||||
//TODO eventually this needs to support closures
|
//TODO eventually this needs to support closures
|
||||||
Param(u8), //TODO handle implications of functions being limited to 255 params
|
Param(u8),
|
||||||
LocalVariable(ItemId),
|
LocalVariable(ItemId),
|
||||||
LocalFunction(ItemId),
|
LocalFunction(ItemId),
|
||||||
Import(Fqsn),
|
Import(Fqsn),
|
||||||
|
Loading…
Reference in New Issue
Block a user