From aad4a82ebfe618cd8b8b61a63ad18d3dce3d5ac1 Mon Sep 17 00:00:00 2001 From: Hugo Guerrier Date: Fri, 6 Dec 2024 14:49:46 +0100 Subject: [PATCH] Fix the 'KP-19312' detector --- lkql_checker/share/lkql/kp/KP-19312.lkql | 4 ++-- testsuite/tests/checks/KP-19312/main.adb | 4 ++++ testsuite/tests/checks/KP-19312/test.out | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lkql_checker/share/lkql/kp/KP-19312.lkql b/lkql_checker/share/lkql/kp/KP-19312.lkql index b71c8e323..c9fbeee72 100644 --- a/lkql_checker/share/lkql/kp/KP-19312.lkql +++ b/lkql_checker/share/lkql/kp/KP-19312.lkql @@ -5,5 +5,5 @@ fun kp_19312(node) = |" Flag "for" loop specs which define an iteration filter and which iterate |" over a type which defines the "iterable" aspect. node is ForLoopSpec - when node.f_iter_expr.p_expression_type()?.p_has_aspect?("iterable") - and node.f_iter_filter is not null + when node.f_iter_filter is not null + and node.f_iter_expr is e@Expr when (e.p_expression_type()?.p_has_aspect?("iterable")) diff --git a/testsuite/tests/checks/KP-19312/main.adb b/testsuite/tests/checks/KP-19312/main.adb index 7779c6960..004944970 100644 --- a/testsuite/tests/checks/KP-19312/main.adb +++ b/testsuite/tests/checks/KP-19312/main.adb @@ -40,6 +40,10 @@ begin Put_Line ("Elem: " & Elem'Image); end loop; + for Elem in Integer range 1 .. 10 loop -- NOFLAG + Put_Line ("Elem: " & Elem'Image); + end loop; + for Elem of I loop -- NOFLAG Put_Line ("Elem: " & Elem'Image); end loop; diff --git a/testsuite/tests/checks/KP-19312/test.out b/testsuite/tests/checks/KP-19312/test.out index ca48bb765..837c4dae0 100644 --- a/testsuite/tests/checks/KP-19312/test.out +++ b/testsuite/tests/checks/KP-19312/test.out @@ -2,11 +2,11 @@ main.adb:35:44: rule violation: possible occurrence of KP 19312 35 | S_1 : constant Integer_Sets.Set := [for E of I when False => E]; -- FLAG | ^^^^^^^^^^^^^^^^^ -main.adb:47:8: rule violation: possible occurrence of KP 19312 -47 | for Elem in I when False loop -- FLAG +main.adb:51:8: rule violation: possible occurrence of KP 19312 +51 | for Elem in I when False loop -- FLAG | ^^^^^^^^^^^^^^^^^^^^ -main.adb:51:8: rule violation: possible occurrence of KP 19312 -51 | for Elem of I when False loop -- FLAG +main.adb:55:8: rule violation: possible occurrence of KP 19312 +55 | for Elem of I when False loop -- FLAG | ^^^^^^^^^^^^^^^^^^^^