Skip to content

Fix type coercion failure with mixed positional/named parameters in p…#1174

Merged
gaoxueyu merged 1 commit into
IvorySQL:IVORY_REL_5_STABLEfrom
jiaoshuntian:ivy5_bp_1132
Jan 29, 2026
Merged

Fix type coercion failure with mixed positional/named parameters in p…#1174
gaoxueyu merged 1 commit into
IvorySQL:IVORY_REL_5_STABLEfrom
jiaoshuntian:ivy5_bp_1132

Conversation

@jiaoshuntian

@jiaoshuntian jiaoshuntian commented Jan 27, 2026

Copy link
Copy Markdown
Collaborator

…ackages and subprocedures

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced type coercion and argument matching for package and subprocedure functions when using reordered or default parameters.
    • Improved support for mixed positional and named parameter calls with proper type alignment.
  • Tests

    • Added comprehensive test coverage for mixed positional and named parameters, including default parameters and overload resolution scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 27, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR adds post-lookup type reinforcement for package and subprocedure function calls. When a function is identified as a package or subprocedure function after lookup, the code rebuilds actual argument types to align with reordered or expanded arguments. Additionally, comprehensive test coverage is introduced for mixed positional and named parameter scenarios.

Changes

Cohort / File(s) Summary
Backend parser type reinforcement
src/backend/parser/parse_func.c
Adds post-lookup logic to rebuild actual_arg_types for package/subprocedure functions when detail is not FUNCDETAIL_NOTFOUND, re-evaluating argument types based on reordered fargs and updating nargs.
PL/SQL subproc argument type synchronization
src/pl/plisql/src/pl_subproc_function.c
Adds logic to rebuild true_typeids in declared argument order when subproc functions have named/defaulted arguments and non-NULL argnumbers, ensuring type alignment with reordered arguments.
Comprehensive test suite for mixed parameters
src/pl/plisql/src/sql/plisql_call.sql
Introduces new public package test_mixed_params_pkg with procedure proc_with_defaults and 5+ test cases covering positional, named, and mixed parameter scenarios with defaults, overloads, and type coercion.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • OreoYang
  • NotHimmel

Poem

🐰 Hops through arguments, reordered with care,
Types now aligned, mixed params declare!
Package and subproc, the types they align,
Named and positional dance in a line!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: resolving type coercion failures when using mixed positional and named parameters in packages and subprocedures, which aligns with all three file changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/backend/parser/parse_func.c`:
- Around line 366-392: This code rebuilds actual_arg_types and sets nargs when
function_from is FUNC_FROM_PACKAGE or FUNC_FROM_SUBPROCFUNC and fdresult !=
FUNCDETAIL_NOTFOUND, which means defaults may already have been injected into
fargs; to avoid double-counting you should record that defaults were already
expanded (e.g., set a local flag like defaults_already_expanded when running the
existing branch that iterates fargs and sets actual_arg_types/nargs) and then,
in the later nargsplusdefs/argdefaults appending logic, skip appending
argdefaults if that flag is true so nargsplusdefs remains consistent with
declared_arg_types and enforce_generic_type_consistency cannot overrun or
produce spurious "too many arguments" errors; use the existing symbols
(function_from, FUNC_FROM_PACKAGE, FUNC_FROM_SUBPROCFUNC, fdresult, fargs,
actual_arg_types, nargs, argdefaults, nargsplusdefs, declared_arg_types,
enforce_generic_type_consistency) to locate where to set the flag and where to
conditionally skip the append.

Comment on lines +366 to +392
/*
* If we found a package function/procedure or subprocedure, the fargs
* list may have been reordered and expanded with default arguments. We
* need to rebuild the actual_arg_types array to match the new argument
* order, otherwise type coercion will fail when trying to match reordered
* arguments.
*
* For subprocedures, the fix in pl_subproc_function.c also rebuilds
* true_typeids (declared_arg_types) in declared order after reordering,
* so that both arrays match the reordered fargs.
*/
if ((function_from == FUNC_FROM_PACKAGE ||
function_from == FUNC_FROM_SUBPROCFUNC) &&
fdresult != FUNCDETAIL_NOTFOUND)
{
ListCell *lc;
int i = 0;

foreach(lc, fargs)
{
Node *arg = lfirst(lc);

actual_arg_types[i++] = exprType(arg);
}
/* Update nargs to reflect the reordered/expanded argument list */
nargs = i;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid double‑counting default argument types after expansion.

When package/subproc lookup expands fargs with defaults, this block rebuilds actual_arg_types and sets nargs to the expanded length. Later, argdefaults is still appended in the nargsplusdefs section, which can make nargsplusdefs larger than declared_arg_types and cause enforce_generic_type_consistency to read past the end (or raise spurious “too many arguments” errors). Please skip the append when defaults were already injected into fargs.

🛠️ Proposed fix (skip argdefaults when already expanded)
@@
- FuncDetailCode fdresult = FUNCDETAIL_NOTFOUND;
+ FuncDetailCode fdresult = FUNCDETAIL_NOTFOUND;
+ bool defaults_already_in_fargs = false;
@@
 	if ((function_from == FUNC_FROM_PACKAGE ||
 		 function_from == FUNC_FROM_SUBPROCFUNC) &&
 		fdresult != FUNCDETAIL_NOTFOUND)
 	{
 		ListCell   *lc;
-		int			i = 0;
+		int			i = 0;
+		int			original_nargs = nargs;
 
 		foreach(lc, fargs)
 		{
 			Node	   *arg = lfirst(lc);
 
 			actual_arg_types[i++] = exprType(arg);
 		}
 		/* Update nargs to reflect the reordered/expanded argument list */
 		nargs = i;
+		if (i > original_nargs && argdefaults != NIL)
+			defaults_already_in_fargs = true;
 	}
@@
 	nargsplusdefs = nargs;
-	foreach(l, argdefaults)
+	if (!defaults_already_in_fargs)
+		foreach(l, argdefaults)
 	{
 		Node	   *expr = (Node *) lfirst(l);
 		...
 	}
🤖 Prompt for AI Agents
In `@src/backend/parser/parse_func.c` around lines 366 - 392, This code rebuilds
actual_arg_types and sets nargs when function_from is FUNC_FROM_PACKAGE or
FUNC_FROM_SUBPROCFUNC and fdresult != FUNCDETAIL_NOTFOUND, which means defaults
may already have been injected into fargs; to avoid double-counting you should
record that defaults were already expanded (e.g., set a local flag like
defaults_already_expanded when running the existing branch that iterates fargs
and sets actual_arg_types/nargs) and then, in the later
nargsplusdefs/argdefaults appending logic, skip appending argdefaults if that
flag is true so nargsplusdefs remains consistent with declared_arg_types and
enforce_generic_type_consistency cannot overrun or produce spurious "too many
arguments" errors; use the existing symbols (function_from, FUNC_FROM_PACKAGE,
FUNC_FROM_SUBPROCFUNC, fdresult, fargs, actual_arg_types, nargs, argdefaults,
nargsplusdefs, declared_arg_types, enforce_generic_type_consistency) to locate
where to set the flag and where to conditionally skip the append.

@gaoxueyu gaoxueyu merged commit 946ef99 into IvorySQL:IVORY_REL_5_STABLE Jan 29, 2026
6 checks passed
@jiaoshuntian jiaoshuntian deleted the ivy5_bp_1132 branch April 22, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants