fix: parse error on unnamed arg with default syntax (#2091)
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run

This commit is contained in:
r1b 2025-11-18 04:41:48 -05:00 committed by GitHub
parent 4f79997c8e
commit 1198c1ad11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View file

@ -5522,7 +5522,21 @@ impl<'a> Parser<'a> {
// peek the next token, which if it is another type keyword, then the
// first token is a name and not a type in itself.
let data_type_idx = self.get_current_index();
if let Some(next_data_type) = self.maybe_parse(|parser| parser.parse_data_type())? {
// DEFAULT will be parsed as `DataType::Custom`, which is undesirable in this context
fn parse_data_type_no_default(parser: &mut Parser) -> Result<DataType, ParserError> {
if parser.peek_keyword(Keyword::DEFAULT) {
// This dummy error is ignored in `maybe_parse`
parser_err!(
"The DEFAULT keyword is not a type",
parser.peek_token().span.start
)
} else {
parser.parse_data_type()
}
}
if let Some(next_data_type) = self.maybe_parse(parse_data_type_no_default)? {
let token = self.token_at(data_type_idx);
// We ensure that the token is a `Word` token, and not other special tokens.

View file

@ -4475,7 +4475,12 @@ fn parse_create_function_detailed() {
pg_and_generic().verified_stmt(r#"CREATE OR REPLACE FUNCTION increment(i INTEGER) RETURNS INTEGER LANGUAGE plpgsql AS $$ BEGIN RETURN i + 1; END; $$"#);
pg_and_generic().verified_stmt(r#"CREATE OR REPLACE FUNCTION no_arg() RETURNS VOID LANGUAGE plpgsql AS $$ BEGIN DELETE FROM my_table; END; $$"#);
pg_and_generic().verified_stmt(r#"CREATE OR REPLACE FUNCTION return_table(i INTEGER) RETURNS TABLE(id UUID, is_active BOOLEAN) LANGUAGE plpgsql AS $$ BEGIN RETURN QUERY SELECT NULL::UUID, NULL::BOOLEAN; END; $$"#);
pg_and_generic().one_statement_parses_to(
"CREATE FUNCTION add(INTEGER, INTEGER DEFAULT 1) RETURNS INTEGER AS 'select $1 + $2;'",
"CREATE FUNCTION add(INTEGER, INTEGER = 1) RETURNS INTEGER AS 'select $1 + $2;'",
);
}
#[test]
fn parse_incorrect_create_function_parallel() {
let sql = "CREATE FUNCTION add(INTEGER, INTEGER) RETURNS INTEGER LANGUAGE SQL PARALLEL BLAH AS 'select $1 + $2;'";