Toad World® Forums

Code Analysis: Unused variable not detected

#1

I don’t really know what happens here, hope you can reproduce it.

Paste this code into a new editor tab:

CREATE OR REPLACE PROCEDURE test_proc AS
TYPE number_tab IS TABLE OF NUMBER(12);
unused_variable PLS_INTEGER;
BEGIN
IF ( 1 MEMBER OF NEW number_tab() ) THEN
NULL;
END IF;
END test_proc;

  1. The unused variable is not detected.

  2. Interesting add-on:

Now compile the procedure and change something in the code to trigger Code Analysis.
Rule 2131 (Use CONSTANT keyword wherever possible) appears.

#2

A few rules still use old legacy code which will not process post 9i code. Rule 6405 (Avoid defining variables that are not referenced inside the program) is one of them. If you change 1 MEMBER OF NEW number_tab() by just 1 then the 6405 will pop up. This is in the pipeline but on longer term.

About 2131 this rule currently also fires whenever the variable (constant) is not referred to at all, it fires when no assignments are found without looking that the var is referenced. This needs fixing. (QP-1875)

Thanks,
Andre

#3

Thanks for your answer!

I totally understand the part about legacy code, but I am not sure what you mean by “change by just 1”?

That 2131 shows for unused variables is a minor issue, but I’m really curious why it does not show unless I compile the unit and change something afterwards?

This does not seem to be related to the other issue. When I paste the following code, the warning is only displayed after compiling the unit. Once it has been compiled, warnings are displayed immediately when another unused/constant variable is introduced:

CREATE OR REPLACE PROCEDURE test_proc AS
my_constant PLS_INTEGER;
my_variable PLS_INTEGER;
BEGIN
my_variable := my_constant;
END test_proc;

#4

Sorry, I meant

IF ( 1 ) THEN

which does not compile, actually meaning

IF ( true ) THEN

:slight_smile:

About the 2131 issue, I recompiled and then added a space next to another space, it does not show up here. What did you actually do? Does it appear near the unused_variable declaration?

#5

It looks like this after pasting:

01.png

After first time compiling (tab header has changed):

02.png

After appending a space (warnings are displayed):

03.png

#6

I am lost!! I am using Toad for Oracle 13.0.0.80 and I am unable to get it to recognize variables that are not used. Is there a resolution to this?

#7

Hi Kevin,

We had found an issue in our parser when processing certain specific rules. While Rule 6405 isn’t included in the list of problematic rules, the issue sometimes prevented the completion of the Code Analysis scan process. We temporarily disabled the problematic rules for builds that were released earlier this week until the underlying issue can be fixed. Can you try updating to the latest beta build and see if that solves your problem?

Let us know if you continue to experience problems with it.

Thanks,

-John

#8

Hi Kevin,

I just realized you mentioned 13.0.0.80, and since this was posted in the Beta forum, I had read that as 13.2.0.80 which was released last week. I can reproduce your issue in Toad 13.0 and Toad 13.1. This issue was fixed in Toad Beta 13.2.0.18; however in order to use the Beta product, you’ll need to first upgrade your GA version of Toad to the current version, which is 13.1.0.78.

-John