mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-22 03:15:44 +00:00
[syntax-errors] Make duplicate parameter names a semantic error (#17131)
Status -- This is a pretty minor change, but it was breaking a red-knot mdtest until #17463 landed. Now this should close #11934 as the last syntax error being tracked there! Summary -- Moves `Parser::validate_parameters` to `SemanticSyntaxChecker::duplicate_parameter_name`. Test Plan -- Existing tests, with `## Errors` replaced with `## Semantic Syntax Errors`.
This commit is contained in:
parent
9db63fc58c
commit
d5410ef9fe
6 changed files with 70 additions and 44 deletions
|
@ -1,8 +1,6 @@
|
|||
use compact_str::CompactString;
|
||||
use std::fmt::{Display, Write};
|
||||
|
||||
use rustc_hash::{FxBuildHasher, FxHashSet};
|
||||
|
||||
use ruff_python_ast::name::Name;
|
||||
use ruff_python_ast::{
|
||||
self as ast, ExceptHandler, Expr, ExprContext, IpyEscapeKind, Operator, PythonVersion, Stmt,
|
||||
|
@ -3339,10 +3337,6 @@ impl<'src> Parser<'src> {
|
|||
|
||||
parameters.range = self.node_range(start);
|
||||
|
||||
// test_err params_duplicate_names
|
||||
// def foo(a, a=10, *a, a, a: str, **a): ...
|
||||
self.validate_parameters(¶meters);
|
||||
|
||||
parameters
|
||||
}
|
||||
|
||||
|
@ -3630,25 +3624,6 @@ impl<'src> Parser<'src> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Validate that the given parameters doesn't have any duplicate names.
|
||||
///
|
||||
/// Report errors for all the duplicate names found.
|
||||
fn validate_parameters(&mut self, parameters: &ast::Parameters) {
|
||||
let mut all_arg_names =
|
||||
FxHashSet::with_capacity_and_hasher(parameters.len(), FxBuildHasher);
|
||||
|
||||
for parameter in parameters {
|
||||
let range = parameter.name().range();
|
||||
let param_name = parameter.name().as_str();
|
||||
if !all_arg_names.insert(param_name) {
|
||||
self.add_error(
|
||||
ParseErrorType::DuplicateParameter(param_name.to_string()),
|
||||
range,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Classify the `match` soft keyword token.
|
||||
///
|
||||
/// # Panics
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue