felipebz / zpa

Parser and static code analysis tool for PL/SQL and Oracle SQL.
https://zpa.felipebz.com
GNU Lesser General Public License v3.0
211 stars 77 forks source link

Support constraints on subtype of subtype. #158

Closed mcpiroman closed 2 years ago

mcpiroman commented 2 years ago

Parser throws on this valid code:

DECLARE
   SUBTYPE a IS VARCHAR2;
   SUBTYPE b IS a(3);
BEGIN
   NULL;
END;

The reason is that parametrization is defined only for concrete type kinds like NUMERIC_DATATYPE or CHARACTER_DATATYPE, but in this case a is CUSTOM_DATATYPE.

felipebz commented 2 years ago

Thanks, @mcpiroman!

mcpiroman commented 2 years ago

Thank you for the quick fix!

Could it also be more feasible and easy to use to extract the now common parametrization expressions from NUMERIC_DATATYPE, CHARACTER_DATATYPE and CUSTOM_DATATYPE to another rules, like NUMERIC_DATATYPE_CONSTRAINTS and CHARACTER_DATATYPE_CONSTRAINTS, or would backward-compatibility concerns not allow that?

I'm asking because I'm likely to report and PR more issues of this kind and would like to know how to go about that.

felipebz commented 2 years ago

Could it also be more feasible and easy to use to extract the now common parametrization expressions from NUMERIC_DATATYPE, CHARACTER_DATATYPE and CUSTOM_DATATYPE to another rules, like NUMERIC_DATATYPE_CONSTRAINTS and CHARACTER_DATATYPE_CONSTRAINTS, or would backward-compatibility concerns not allow that?

You're right, I agree with you. I should've added a common rule instead of duplicating the code, I just changed it:

https://github.com/felipebz/zpa/blob/2d5c8187e483edf08f6c3baf86a6c2a78aa382c7/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlGrammar.kt#L368-L370

Regarding backward-compatibility, tbh I'm more concerned with removing nodes from the AST than adding new nodes.