Toad World® Forums

Code Analysis: Rule 5406 (unused parameters) not triggered as expected

In the following example param_1 is unused in both procedures, but only detected in the first one since the parameter name is used as named parameter when calling the first procedure. Version: 12.10.0.25.

DECLARE
PROCEDURE my_procedure_1( param_1 IN NUMBER ) AS – detected as expected
BEGIN
NULL;
END;

PROCEDURE my_procedure_2( param_1 IN NUMBER ) AS – not detected
BEGIN
my_procedure_1( param_1 => NULL );
END;
BEGIN
NULL;
END;

Hi Peter,

I understand that you expected my_procedure_2 to “see” that param_1 passed to my_procedure_1 is eventually unused.

Currently, unused parameters are only detected in the scope of the current code unit. So, related to my_procedure_2, parameter param_1 is “used” as it is passed to some procedure. This may sure make sense as my_procedure_1 could be a temporary stub, to be completed later. Unused could become used soon.

Having said that, there is always room for a rule which could detected “eventually unused” conditions. But we don’t have that today.

Thanks,
Andre

Hi Andre,

no, I think you got me wrong, let me try to explain it again. The fact that my_procedure_1 does not use the parameter is a problem of my_procedure_1 only, in my opinion there is no need for my_procedure_2 to know.

The problem is that my_procedure_2 does not use its own parameter.
This call of my_procedure_1 passes NULL, param_1 is not the parameter passed to my_procedure_2 but the name of the parameter of my_procedure_1.

If the name of the parameter of my_procedure_1 would be different, it would be detected just fine:

DECLARE
PROCEDURE my_procedure_1( param_2 IN NUMBER ) AS – detected as expected
BEGIN
NULL;
END;

PROCEDURE my_procedure_2( param_1 IN NUMBER ) AS – detected as expected
BEGIN
my_procedure_1( param_2 => NULL );
END;
BEGIN
NULL;
END;

My gosh, you’re right of course! The parameter param_1 of …proc_2 is unused indeed.

Thanks for this case, is on the fix list. (QP-1859)
Andre

This has been addressed, soon to show up in a new Toad having QP5 version 5.305 (or later).
In addition, the following issues were detected and fixed:

  • Nested variable declarations and parameter declarations in nested program units or cursors are taken into account.,
  • Items in select lists are no longer discarded,
  • In qualified names now only the leftmost identifier is taken into account.
    Thanks,
    Andre