Skip to content

Commit 42b974c

Browse files
committed
Fix crash when nested sub-functions access NEW after DECLARE uses NEW.id.
1 parent ba9c6f3 commit 42b974c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/pl/plisql/src/pl_subproc_function.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,24 @@ plisql_init_subprocfunc_globalvar(PLiSQL_execstate * estate, FunctionCallInfo fc
12651265
if (estate->datums[i]->dtype == PLISQL_DTYPE_ROW)
12661266
continue;
12671267

1268+
/*
1269+
* Skip RECFIELD datums. A RECFIELD carries no independent value;
1270+
* it is purely field-reference metadata (recparentno + fieldname).
1271+
* Such datums can appear in the outer-scope range as a compile-time
1272+
* side-effect: when scanning a DEFAULT expression that references a
1273+
* record field (e.g. "var1 integer := new.id"), plisql_build_recfield
1274+
* is called by the lexer before lastassignvardno is recorded, placing
1275+
* the RECFIELD at an index below lastassignvardno. The parent record
1276+
* (e.g. NEW/OLD) is propagated separately, so there is nothing to do
1277+
* here.
1278+
*/
1279+
if (estate->datums[i]->dtype == PLISQL_DTYPE_RECFIELD)
1280+
{
1281+
/* Parent record must precede its RECFIELD in the datum array */
1282+
Assert(((PLiSQL_recfield *) estate->datums[i])->recparentno < i);
1283+
continue;
1284+
}
1285+
12681286
/* Ignore datums that don't require assignment */
12691287
if (is_subprocfunc_argnum(pfunc, i))
12701288
continue;
@@ -1328,6 +1346,13 @@ plisql_assign_out_subprocfunc_globalvar(PLiSQL_execstate * estate,
13281346
if (estate->datums[i]->dtype == PLISQL_DTYPE_ROW)
13291347
continue;
13301348

1349+
/* See comment in plisql_init_subprocfunc_globalvar */
1350+
if (estate->datums[i]->dtype == PLISQL_DTYPE_RECFIELD)
1351+
{
1352+
Assert(((PLiSQL_recfield *) estate->datums[i])->recparentno < i);
1353+
continue;
1354+
}
1355+
13311356
/* Ignore datums that don't require assignment */
13321357
if (is_subprocfunc_argnum(pfunc, i))
13331358
continue;

0 commit comments

Comments
 (0)