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

Idl.declare: check for duplicate argument names #174

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

edwintorok
Copy link
Collaborator

We've recently had a bug where an RPC got declared with duplicate names due to a confusion on how [Param.mk] works: the string argument taken by [Param.mk ~name] is NOT a type name, but an argument name.
Which then resulted in the RPC silently reversing the order of the arguments to the RPC because they all had the same name (and there is probably one too many or too few List.rev in the RPC handling code such that order of arguments is not preserved).

Prevent this mistake at startup time and reject any RPC with duplicate parameter names declared: it is a programming error.

Draft PR, will need a bit more wider testing (it does catch the original bug at 'dune runtest' time in XAPI)

We've recently had a bug where an RPC got declared with duplicate names
due to a confusion on how [Param.mk] works: the string argument taken by
[Param.mk] is NOT a type name, but an argument name.
Which then resulted in the RPC silently swapping the order of the arguments around.

Prevent this mistake at startup time and reject any RPC with duplicate
parameter names declared, it is a programming error.

Signed-off-by: Edwin Török <[email protected]>
@edwintorok
Copy link
Collaborator Author

Due to the GADT there is unfortunately some copy/paste of the 'params_of' function in each of GenServer, GenClient, etc.

@@ -104,6 +104,20 @@ let get_wire_name description name =
| None -> name)


let check_dups_exn api params =
let named = params |> List.filter_map Fun.id |> List.rev in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list gets sorted later and otherwise only the length is taken - so we need the List.rev only for the error reporting (where we could also apply it).

Could we move the params_of call from the call sites into this function? Currently this function is neither a universal list function, nor very domain specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants