mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-23 21:46:46 +00:00
[ty] Enums: allow multiple aliases to point to the same member (#20669)
## Summary closes https://github.com/astral-sh/ty/issues/1293 ## Test Plan Regression test
This commit is contained in:
parent
963bc8c228
commit
56d630e303
2 changed files with 45 additions and 3 deletions
|
|
@ -194,12 +194,19 @@ pub(crate) fn enum_metadata<'db>(
|
|||
// we don't know if it's a duplicate or not.
|
||||
if matches!(
|
||||
value_ty,
|
||||
Type::IntLiteral(_) | Type::StringLiteral(_) | Type::BytesLiteral(_)
|
||||
Type::BooleanLiteral(_)
|
||||
| Type::IntLiteral(_)
|
||||
| Type::StringLiteral(_)
|
||||
| Type::BytesLiteral(_)
|
||||
) {
|
||||
if let Some(previous) = enum_values.insert(value_ty, name.clone()) {
|
||||
aliases.insert(name.clone(), previous);
|
||||
if let Some(canonical) = enum_values.get(&value_ty) {
|
||||
// This is a duplicate value, create an alias to the canonical (first) member
|
||||
aliases.insert(name.clone(), canonical.clone());
|
||||
return None;
|
||||
}
|
||||
|
||||
// This is the first occurrence of this value, track it as the canonical member
|
||||
enum_values.insert(value_ty, name.clone());
|
||||
}
|
||||
|
||||
let declarations = use_def_map.end_of_scope_symbol_declarations(symbol_id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue