Skip to content

Commit d6e948b

Browse files
committed
LKQLWorker: emit an error for invalid rules value
1 parent 1412f4f commit d6e948b

File tree

7 files changed

+56
-0
lines changed

7 files changed

+56
-0
lines changed

lkql_jit/cli/src/main/java/com/adacore/lkql_jit/cli/GNATCheckWorker.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ private static Map<String, RuleInstance> parseLKQLRuleFile(
359359
if (topLevel.hasMember("rules")) {
360360
processInstancesObject(
361361
lkqlFileBasename,
362+
"rules",
362363
topLevel.getMember("rules"),
363364
RuleInstance.SourceMode.GENERAL,
364365
res,
@@ -369,6 +370,7 @@ private static Map<String, RuleInstance> parseLKQLRuleFile(
369370
if (topLevel.hasMember("ada_rules")) {
370371
processInstancesObject(
371372
lkqlFileBasename,
373+
"ada_rules",
372374
topLevel.getMember("ada_rules"),
373375
RuleInstance.SourceMode.ADA,
374376
res,
@@ -378,6 +380,7 @@ private static Map<String, RuleInstance> parseLKQLRuleFile(
378380
if (topLevel.hasMember("spark_rules")) {
379381
processInstancesObject(
380382
lkqlFileBasename,
383+
"spark_rules",
381384
topLevel.getMember("spark_rules"),
382385
RuleInstance.SourceMode.SPARK,
383386
res,
@@ -406,11 +409,22 @@ private static Map<String, RuleInstance> parseLKQLRuleFile(
406409
*/
407410
private static void processInstancesObject(
408411
final String lkqlRuleFile,
412+
final String instancesObjectSymbol,
409413
final Value instancesObject,
410414
final RuleInstance.SourceMode sourceMode,
411415
final Map<String, RuleInstance> toPopulate,
412416
final boolean verbose
413417
) throws LKQLRuleFileError {
418+
if (!instancesObject.hasMembers()) {
419+
errorInLKQLRuleFile(
420+
lkqlRuleFile,
421+
"The value associated to the '" +
422+
instancesObjectSymbol +
423+
"' symbol must be an LKQL object, got " +
424+
instancesObject
425+
);
426+
}
427+
414428
// Iterate on all instance object keys
415429
for (String ruleName : instancesObject.getMemberKeys()) {
416430
final String lowerRuleName = ruleName.toLowerCase();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val rules = 2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
val rules = @{}
2+
3+
val ada_rules = 2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
val rules = @{}
2+
3+
val spark_rules = 2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
procedure Main is null;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Invalid type for rules object
2+
=============================
3+
4+
gnatcheck: error: The value associated to the 'rules' symbol must be an LKQL object, got 2 (config1.lkql)
5+
gnatcheck: error: no rule to check specified
6+
try "gnatcheck --help" for more information.
7+
>>>program returned status code 2
8+
9+
Invalid type for ada_rules object
10+
=================================
11+
12+
gnatcheck: error: The value associated to the 'ada_rules' symbol must be an LKQL object, got 2 (config2.lkql)
13+
gnatcheck: error: no rule to check specified
14+
try "gnatcheck --help" for more information.
15+
>>>program returned status code 2
16+
17+
Invalid type for spark_rules object
18+
===================================
19+
20+
gnatcheck: error: The value associated to the 'spark_rules' symbol must be an LKQL object, got 2 (config3.lkql)
21+
gnatcheck: error: no rule to check specified
22+
try "gnatcheck --help" for more information.
23+
>>>program returned status code 2
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
driver: gnatcheck
2+
format: brief
3+
input_sources:
4+
- main.adb
5+
tests:
6+
- label: Invalid type for rules object
7+
lkql_rule_file: config1.lkql
8+
- label: Invalid type for ada_rules object
9+
lkql_rule_file: config2.lkql
10+
- label: Invalid type for spark_rules object
11+
lkql_rule_file: config3.lkql

0 commit comments

Comments
 (0)