@@ -1020,9 +1020,7 @@ export class V13ToV14Transformer {
10201020 const typeName = argType . names [ argType . names . length - 1 ] ;
10211021 if ( typeName && typeName . String && typeName . String . str ) {
10221022 const typeStr = typeName . String . str . toLowerCase ( ) ;
1023- return typeStr === 'anyarray' ||
1024- typeStr === 'anycompatiblearray' ||
1025- typeStr . endsWith ( 'array' ) ;
1023+ return typeStr === 'anyarray' || typeStr === 'anycompatiblearray' ;
10261024 }
10271025 }
10281026
@@ -1045,14 +1043,15 @@ export class V13ToV14Transformer {
10451043 }
10461044
10471045 if ( node . mode !== undefined ) {
1048- const isInDropContext = context . parentNodeTypes ?. includes ( 'DropStmt' ) ;
1049-
1050- if ( isInDropContext ) {
1051- result . mode = "FUNC_PARAM_DEFAULT" ;
1052- } else if ( node . mode === "FUNC_PARAM_VARIADIC" ) {
1053- result . mode = "FUNC_PARAM_VARIADIC" ; // Keep variadic parameters as variadic in non-drop contexts
1046+ if ( node . mode === "FUNC_PARAM_VARIADIC" ) {
1047+ result . mode = "FUNC_PARAM_VARIADIC" ; // Always preserve variadic parameters
10541048 } else if ( node . mode === "FUNC_PARAM_IN" ) {
1055- result . mode = "FUNC_PARAM_DEFAULT" ;
1049+ // Check if this parameter should be variadic based on polymorphic array types
1050+ if ( this . isVariadicParameterType ( node . argType ) ) {
1051+ result . mode = "FUNC_PARAM_VARIADIC" ;
1052+ } else {
1053+ result . mode = "FUNC_PARAM_DEFAULT" ;
1054+ }
10561055 } else {
10571056 result . mode = node . mode ;
10581057 }
@@ -1850,20 +1849,23 @@ export class V13ToV14Transformer {
18501849 const shouldPreserveObjfuncargs = this . shouldPreserveObjfuncargs ( context ) ;
18511850 const shouldCreateObjfuncargsFromObjargs = this . shouldCreateObjfuncargsFromObjargs ( context ) ;
18521851
1852+ let createdFromObjargs = false ;
1853+
18531854 if ( shouldCreateObjfuncargsFromObjargs && result . objargs ) {
18541855 // Create objfuncargs from objargs (this takes priority over shouldCreateObjfuncargs)
18551856 result . objfuncargs = Array . isArray ( result . objargs )
18561857 ? result . objargs . map ( ( arg : any ) => this . createFunctionParameterFromTypeName ( arg , context ) )
18571858 : [ this . createFunctionParameterFromTypeName ( result . objargs , context ) ] ;
1859+ createdFromObjargs = true ;
18581860
18591861 } else if ( shouldCreateObjfuncargs ) {
18601862 result . objfuncargs = [ ] ;
18611863 } else if ( result . objfuncargs !== undefined ) {
1862- if ( shouldPreserveObjfuncargs ) {
1864+ if ( shouldPreserveObjfuncargs && ! createdFromObjargs ) {
18631865 result . objfuncargs = Array . isArray ( result . objfuncargs )
18641866 ? result . objfuncargs . map ( ( item : any ) => this . transform ( item , context ) )
18651867 : [ this . transform ( result . objfuncargs , context ) ] ;
1866- } else {
1868+ } else if ( ! shouldPreserveObjfuncargs ) {
18671869 delete result . objfuncargs ;
18681870 }
18691871 } else if ( ! shouldPreserveObjfuncargs ) {
@@ -2117,32 +2119,29 @@ export class V13ToV14Transformer {
21172119
21182120 let mode = "FUNC_PARAM_DEFAULT" ;
21192121
2120- const isInDropContext = context ?. parentNodeTypes ?. includes ( 'DropStmt' ) ;
2122+ // Check if this is a variadic parameter type (anyarray, anycompatiblearray, etc.)
2123+ if ( this . isVariadicParameterType ( argType ) ) {
2124+ mode = "FUNC_PARAM_VARIADIC" ;
2125+ }
21212126
2122- if ( ! isInDropContext ) {
2123- // Check if this is a variadic parameter type (anyarray, anycompatiblearray, etc.)
2124- if ( this . isVariadicParameterType ( argType ) ) {
2127+ if ( argType && argType . names && Array . isArray ( argType . names ) ) {
2128+ const typeName = argType . names [ argType . names . length - 1 ] ;
2129+ if ( typeName && typeName . String && typeName . String . str === 'anyarray' ) {
21252130 mode = "FUNC_PARAM_VARIADIC" ;
21262131 }
2127-
2128- if ( argType && argType . names && Array . isArray ( argType . names ) ) {
2132+ }
2133+
2134+
2135+ // Also check for VARIADIC context in aggregate functions
2136+ if ( context && context . parentNodeTypes ) {
2137+ const isAggregateContext = context . parentNodeTypes . includes ( 'RenameStmt' ) &&
2138+ ( context as any ) . renameObjectType === 'OBJECT_AGGREGATE' ;
2139+ if ( isAggregateContext && argType && argType . names && Array . isArray ( argType . names ) ) {
21292140 const typeName = argType . names [ argType . names . length - 1 ] ;
2130- if ( typeName && typeName . String && typeName . String . str === 'anyarray ' ) {
2141+ if ( typeName && typeName . String && typeName . String . str === 'any ' ) {
21312142 mode = "FUNC_PARAM_VARIADIC" ;
21322143 }
21332144 }
2134-
2135- // Also check for VARIADIC context in aggregate functions
2136- if ( context && context . parentNodeTypes ) {
2137- const isAggregateContext = context . parentNodeTypes . includes ( 'RenameStmt' ) &&
2138- ( context as any ) . renameObjectType === 'OBJECT_AGGREGATE' ;
2139- if ( isAggregateContext && argType && argType . names && Array . isArray ( argType . names ) ) {
2140- const typeName = argType . names [ argType . names . length - 1 ] ;
2141- if ( typeName && typeName . String && typeName . String . str === 'any' ) {
2142- mode = "FUNC_PARAM_VARIADIC" ;
2143- }
2144- }
2145- }
21462145 }
21472146
21482147 const functionParam : any = {
@@ -2151,28 +2150,23 @@ export class V13ToV14Transformer {
21512150 } ;
21522151
21532152 // Parameter names are crucial for DROP FUNCTION to identify overloaded functions
2154- let parameterName = null ;
21552153 if ( typeNameNode ) {
21562154 if ( typeNameNode . name ) {
2157- parameterName = typeNameNode . name ;
2155+ functionParam . name = typeNameNode . name ;
21582156 } else if ( typeNameNode . String && typeNameNode . String . str ) {
2159- parameterName = typeNameNode . String . str ;
2157+ functionParam . name = typeNameNode . String . str ;
21602158 } else if ( typeNameNode . names && Array . isArray ( typeNameNode . names ) && typeNameNode . names . length > 0 ) {
21612159 // Check if the first element might be a parameter name (before the type)
21622160 const firstElement = typeNameNode . names [ 0 ] ;
21632161 if ( firstElement && firstElement . String && firstElement . String . str ) {
21642162 const potentialName = firstElement . String . str ;
21652163 if ( ! potentialName . includes ( '.' ) && potentialName . length < 20 ) {
2166- parameterName = potentialName ;
2164+ functionParam . name = potentialName ;
21672165 }
21682166 }
21692167 }
21702168 }
21712169
2172- if ( parameterName ) {
2173- functionParam . name = parameterName ;
2174- }
2175-
21762170 return {
21772171 FunctionParameter : functionParam
21782172 } ;
0 commit comments