[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:
David Peter 2025-10-01 15:51:53 +02:00 committed by GitHub
parent 963bc8c228
commit 56d630e303
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 3 deletions

View file

@ -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);