Toad World® Forums

Code Analysis - Rule 6407: Ensure item is defined in as deep a scope as possible.

I am trying to clean my code with Code Analysis so I also try to get rid of false positives.

This is a way to reproduce one:

CREATE TABLE test_table( test_table_id NUMBER );

CREATE PACKAGE BODY test_package
AS
TYPE t_test IS RECORD(
test_table_id test_table.test_table_id%TYPE – Rule 6407: Ensure item is defined in as deep a scope as possible.
);

PROCEDURE test_me AS BEGIN
UPDATE test_table SET test_table_id = 1 WHERE 1=1;
END;
END;

CA thinks that the test_table_id type would better be created inside the test_me procedure, as it is only used there. Proof: if you clone test_me to test_me_2 then the warning will go away.

Perhaps we could drop it for types… What are your thoughts?

Thanks,

Andre

Thanks for looking into this.

I don’t think that this is true, the code below also shows the same violation.

Also, if the type has a problem the type name is highlighted, not the first member - also visible in the example below, and also wrong, unfortunately :wink:

CREATE TABLE test_table( test_table_id NUMBER );

CREATE PACKAGE BODY test_package
AS
TYPE t_test IS RECORD(
test_table_id test_table.test_table_id%TYPE – Rule 6407: Ensure item is defined in as deep a scope as possible.
);

FUNCTION get_test
RETURN t_test
AS
BEGIN
RETURN NULL;
END get_test;

PROCEDURE test_me AS BEGIN
UPDATE test_table SET test_table_id = 1 WHERE 1=1;
END;
END;

You’re right, I should have used t_test. Let me look into this…