Skip to content

Commit

Permalink
Fix false positive given arity mismatch in inconsistent-args
Browse files Browse the repository at this point in the history
While a mismatched arg is technically still a violation, the arity mismatch should
probably be dealt with first, so let's have the compiler handle that.

Fixes #1250

Signed-off-by: Anders Eknert <[email protected]>
  • Loading branch information
anderseknert committed Nov 11, 2024
1 parent 360dda6 commit ef6c062
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ report contains violation if {

some name, args_list in function_args_by_name

# leave that to the compiler
not _arity_mismatch(args_list)

# "Partition" the args by their position
by_position := [s |
some i, _ in args_list[0]
Expand All @@ -39,6 +42,12 @@ report contains violation if {
violation := result.fail(rego.metadata.chain(), result.ranged_location_between(args[0], regal.last(args)))
}

_arity_mismatch(args_list) if {
len := count(args_list[0])
some arr in args_list
count(arr) != len
}

_inconsistent_args(position) if {
named_vars := {arg.value |
some arg in position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ test_success_using_pattern_matching if {
r == set()
}

# this is a compiler error, so let's not flag it here
# see https://github.com/StyraInc/regal/issues/1250
test_success_incorrect_arity if {
module := ast.with_rego_v1(`
foo(a, b) if a == b
foo(a, b, c) if a > b > c
foo(b, a) if a == b
`)
r := rule.report with input as module

r == set()
}

expected := {
"category": "bugs",
"description": "Inconsistently named function arguments",
Expand Down

0 comments on commit ef6c062

Please sign in to comment.