1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use crate::validation::diagnostics::DiagnosticData;
use crate::validation::{DiagnosticList, NodeLocation};
use crate::{ast, Node};
use std::collections::HashMap;

pub(crate) fn validate_arguments(
    diagnostics: &mut DiagnosticList,
    arguments: &[Node<ast::Argument>],
) {
    let mut seen = HashMap::<_, Option<NodeLocation>>::new();

    for argument in arguments {
        let name = &argument.name;
        if let Some(&original_definition) = seen.get(name) {
            let redefined_definition = argument.location();
            diagnostics.push(
                redefined_definition,
                DiagnosticData::UniqueArgument {
                    name: name.clone(),
                    original_definition,
                    redefined_definition,
                },
            );
        } else {
            seen.insert(name, argument.location());
        }
    }
}