Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false positive given arity mismatch in inconsistent-args #1252

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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