Skip to content

Commit eced951

Browse files
committed
fix false alarm about bad number of target variables when procedure has composite inout argument
1 parent 845b389 commit eced951

File tree

6 files changed

+271
-1
lines changed

6 files changed

+271
-1
lines changed

expected/plpgsql_check_active.out

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9492,3 +9492,57 @@ select * from plpgsql_check_function('pure_expr()');
94929492
(7 rows)
94939493

94949494
drop table testtable_pure_expr;
9495+
-- should not to raise false alarm
9496+
drop function fxx(ct, ct);
9497+
drop type ct;
9498+
create type ct as (x int, y numeric, v varchar);
9499+
create procedure proc_composite(inout cv ct, x int, y numeric, v varchar)
9500+
as $$
9501+
begin
9502+
cv.x := x;
9503+
cv.y := y;
9504+
cv.v := v;
9505+
end;
9506+
$$ language plpgsql;
9507+
call proc_composite(null, 10, 10.2, 'ahoj');
9508+
cv
9509+
----------------
9510+
(10,10.2,ahoj)
9511+
(1 row)
9512+
9513+
create or replace function test_proc_composite()
9514+
returns void as $$
9515+
declare cv ct;
9516+
begin
9517+
call proc_composite(cv, 10, 10.2, 'ahoj');
9518+
end;
9519+
$$ language plpgsql;
9520+
select * from plpgsql_check_function('test_proc_composite');
9521+
plpgsql_check_function
9522+
------------------------
9523+
(0 rows)
9524+
9525+
drop function test_proc_composite;
9526+
drop procedure proc_composite;
9527+
create procedure proc_composite(inout cv1 ct, cv2 ct)
9528+
as $$
9529+
begin
9530+
cv1.x := 10;
9531+
cv2.v := 'Ahoj';
9532+
end;
9533+
$$ language plpgsql;
9534+
create or replace function test_proc_composite()
9535+
returns void as $$
9536+
declare cv1 ct; cv2 ct;
9537+
begin
9538+
call proc_composite(cv1, cv2);
9539+
end;
9540+
$$ language plpgsql;
9541+
select * from plpgsql_check_function('test_proc_composite');
9542+
plpgsql_check_function
9543+
------------------------
9544+
(0 rows)
9545+
9546+
drop function test_proc_composite;
9547+
drop procedure proc_composite;
9548+
drop type ct;

expected/plpgsql_check_active_2.out

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9491,3 +9491,57 @@ select * from plpgsql_check_function('pure_expr()');
94919491
(7 rows)
94929492

94939493
drop table testtable_pure_expr;
9494+
-- should not to raise false alarm
9495+
drop function fxx(ct, ct);
9496+
drop type ct;
9497+
create type ct as (x int, y numeric, v varchar);
9498+
create procedure proc_composite(inout cv ct, x int, y numeric, v varchar)
9499+
as $$
9500+
begin
9501+
cv.x := x;
9502+
cv.y := y;
9503+
cv.v := v;
9504+
end;
9505+
$$ language plpgsql;
9506+
call proc_composite(null, 10, 10.2, 'ahoj');
9507+
cv
9508+
----------------
9509+
(10,10.2,ahoj)
9510+
(1 row)
9511+
9512+
create or replace function test_proc_composite()
9513+
returns void as $$
9514+
declare cv ct;
9515+
begin
9516+
call proc_composite(cv, 10, 10.2, 'ahoj');
9517+
end;
9518+
$$ language plpgsql;
9519+
select * from plpgsql_check_function('test_proc_composite');
9520+
plpgsql_check_function
9521+
------------------------
9522+
(0 rows)
9523+
9524+
drop function test_proc_composite;
9525+
drop procedure proc_composite;
9526+
create procedure proc_composite(inout cv1 ct, cv2 ct)
9527+
as $$
9528+
begin
9529+
cv1.x := 10;
9530+
cv2.v := 'Ahoj';
9531+
end;
9532+
$$ language plpgsql;
9533+
create or replace function test_proc_composite()
9534+
returns void as $$
9535+
declare cv1 ct; cv2 ct;
9536+
begin
9537+
call proc_composite(cv1, cv2);
9538+
end;
9539+
$$ language plpgsql;
9540+
select * from plpgsql_check_function('test_proc_composite');
9541+
plpgsql_check_function
9542+
------------------------
9543+
(0 rows)
9544+
9545+
drop function test_proc_composite;
9546+
drop procedure proc_composite;
9547+
drop type ct;

expected/plpgsql_check_active_3.out

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9492,3 +9492,57 @@ select * from plpgsql_check_function('pure_expr()');
94929492
(7 rows)
94939493

94949494
drop table testtable_pure_expr;
9495+
-- should not to raise false alarm
9496+
drop function fxx(ct, ct);
9497+
drop type ct;
9498+
create type ct as (x int, y numeric, v varchar);
9499+
create procedure proc_composite(inout cv ct, x int, y numeric, v varchar)
9500+
as $$
9501+
begin
9502+
cv.x := x;
9503+
cv.y := y;
9504+
cv.v := v;
9505+
end;
9506+
$$ language plpgsql;
9507+
call proc_composite(null, 10, 10.2, 'ahoj');
9508+
cv
9509+
----------------
9510+
(10,10.2,ahoj)
9511+
(1 row)
9512+
9513+
create or replace function test_proc_composite()
9514+
returns void as $$
9515+
declare cv ct;
9516+
begin
9517+
call proc_composite(cv, 10, 10.2, 'ahoj');
9518+
end;
9519+
$$ language plpgsql;
9520+
select * from plpgsql_check_function('test_proc_composite');
9521+
plpgsql_check_function
9522+
------------------------
9523+
(0 rows)
9524+
9525+
drop function test_proc_composite;
9526+
drop procedure proc_composite;
9527+
create procedure proc_composite(inout cv1 ct, cv2 ct)
9528+
as $$
9529+
begin
9530+
cv1.x := 10;
9531+
cv2.v := 'Ahoj';
9532+
end;
9533+
$$ language plpgsql;
9534+
create or replace function test_proc_composite()
9535+
returns void as $$
9536+
declare cv1 ct; cv2 ct;
9537+
begin
9538+
call proc_composite(cv1, cv2);
9539+
end;
9540+
$$ language plpgsql;
9541+
select * from plpgsql_check_function('test_proc_composite');
9542+
plpgsql_check_function
9543+
------------------------
9544+
(0 rows)
9545+
9546+
drop function test_proc_composite;
9547+
drop procedure proc_composite;
9548+
drop type ct;

expected/plpgsql_check_active_4.out

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9493,3 +9493,57 @@ select * from plpgsql_check_function('pure_expr()');
94939493
(7 rows)
94949494

94959495
drop table testtable_pure_expr;
9496+
-- should not to raise false alarm
9497+
drop function fxx(ct, ct);
9498+
drop type ct;
9499+
create type ct as (x int, y numeric, v varchar);
9500+
create procedure proc_composite(inout cv ct, x int, y numeric, v varchar)
9501+
as $$
9502+
begin
9503+
cv.x := x;
9504+
cv.y := y;
9505+
cv.v := v;
9506+
end;
9507+
$$ language plpgsql;
9508+
call proc_composite(null, 10, 10.2, 'ahoj');
9509+
cv
9510+
----------------
9511+
(10,10.2,ahoj)
9512+
(1 row)
9513+
9514+
create or replace function test_proc_composite()
9515+
returns void as $$
9516+
declare cv ct;
9517+
begin
9518+
call proc_composite(cv, 10, 10.2, 'ahoj');
9519+
end;
9520+
$$ language plpgsql;
9521+
select * from plpgsql_check_function('test_proc_composite');
9522+
plpgsql_check_function
9523+
------------------------
9524+
(0 rows)
9525+
9526+
drop function test_proc_composite;
9527+
drop procedure proc_composite;
9528+
create procedure proc_composite(inout cv1 ct, cv2 ct)
9529+
as $$
9530+
begin
9531+
cv1.x := 10;
9532+
cv2.v := 'Ahoj';
9533+
end;
9534+
$$ language plpgsql;
9535+
create or replace function test_proc_composite()
9536+
returns void as $$
9537+
declare cv1 ct; cv2 ct;
9538+
begin
9539+
call proc_composite(cv1, cv2);
9540+
end;
9541+
$$ language plpgsql;
9542+
select * from plpgsql_check_function('test_proc_composite');
9543+
plpgsql_check_function
9544+
------------------------
9545+
(0 rows)
9546+
9547+
drop function test_proc_composite;
9548+
drop procedure proc_composite;
9549+
drop type ct;

sql/plpgsql_check_active.sql

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5637,3 +5637,56 @@ $$ language plpgsql;
56375637
select * from plpgsql_check_function('pure_expr()');
56385638

56395639
drop table testtable_pure_expr;
5640+
5641+
-- should not to raise false alarm
5642+
5643+
drop function fxx(ct, ct);
5644+
drop type ct;
5645+
5646+
create type ct as (x int, y numeric, v varchar);
5647+
5648+
create procedure proc_composite(inout cv ct, x int, y numeric, v varchar)
5649+
as $$
5650+
begin
5651+
cv.x := x;
5652+
cv.y := y;
5653+
cv.v := v;
5654+
end;
5655+
$$ language plpgsql;
5656+
5657+
call proc_composite(null, 10, 10.2, 'ahoj');
5658+
5659+
create or replace function test_proc_composite()
5660+
returns void as $$
5661+
declare cv ct;
5662+
begin
5663+
call proc_composite(cv, 10, 10.2, 'ahoj');
5664+
end;
5665+
$$ language plpgsql;
5666+
5667+
select * from plpgsql_check_function('test_proc_composite');
5668+
5669+
drop function test_proc_composite;
5670+
drop procedure proc_composite;
5671+
5672+
create procedure proc_composite(inout cv1 ct, cv2 ct)
5673+
as $$
5674+
begin
5675+
cv1.x := 10;
5676+
cv2.v := 'Ahoj';
5677+
end;
5678+
$$ language plpgsql;
5679+
5680+
create or replace function test_proc_composite()
5681+
returns void as $$
5682+
declare cv1 ct; cv2 ct;
5683+
begin
5684+
call proc_composite(cv1, cv2);
5685+
end;
5686+
$$ language plpgsql;
5687+
5688+
select * from plpgsql_check_function('test_proc_composite');
5689+
5690+
drop function test_proc_composite;
5691+
drop procedure proc_composite;
5692+
drop type ct;

src/check_expr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,8 @@ plpgsql_check_expr_as_rvalue(PLpgSQL_checkstate *cstate, PLpgSQL_expr *expr,
12371237

12381238
if (stmt &&
12391239
(stmt->cmd_type == PLPGSQL_STMT_EXECSQL ||
1240-
stmt->cmd_type == PLPGSQL_STMT_DYNEXECUTE))
1240+
stmt->cmd_type == PLPGSQL_STMT_DYNEXECUTE ||
1241+
stmt->cmd_type == PLPGSQL_STMT_CALL))
12411242
{
12421243
expand = false;
12431244
}

0 commit comments

Comments
 (0)