|
7 | 7 | use std::collections::HashMap; |
8 | 8 |
|
9 | 9 | use bumpalo::Bump; |
| 10 | + |
10 | 11 | use mago_syntax::ast::*; |
11 | 12 | use mago_syntax::parser::parse_file_content; |
12 | 13 |
|
@@ -683,9 +684,22 @@ impl Backend { |
683 | 684 | Statement::Enum(enum_def) => { |
684 | 685 | let enum_name = enum_def.name.value.to_string(); |
685 | 686 |
|
686 | | - let (mut methods, mut properties, constants, used_traits) = |
| 687 | + let (mut methods, mut properties, constants, mut used_traits) = |
687 | 688 | Self::extract_class_like_members(enum_def.members.iter(), doc_ctx); |
688 | 689 |
|
| 690 | + // Enums implicitly implement UnitEnum or BackedEnum. |
| 691 | + // We add the interface as a fully-qualified name (leading |
| 692 | + // backslash) so that `resolve_name` does not prepend the |
| 693 | + // current namespace. The class_loader / merge_traits_into |
| 694 | + // path will pick up the interface from the SPL stubs and |
| 695 | + // merge its methods (cases, from, tryFrom, …) automatically. |
| 696 | + let implicit_interface = if enum_def.backing_type_hint.is_some() { |
| 697 | + "\\BackedEnum" |
| 698 | + } else { |
| 699 | + "\\UnitEnum" |
| 700 | + }; |
| 701 | + used_traits.push(implicit_interface.to_string()); |
| 702 | + |
689 | 703 | // Extract @property, @method, and @mixin tags from the enum-level docblock. |
690 | 704 | let mut mixins = Vec::new(); |
691 | 705 | if let Some(ctx) = doc_ctx |
@@ -1034,7 +1048,7 @@ impl Backend { |
1034 | 1048 | /// otherwise prepend current namespace |
1035 | 1049 | /// 3. Unqualified (`Bar`) → check use_map; otherwise prepend namespace |
1036 | 1050 | /// 4. No namespace and not in use_map → keep as-is |
1037 | | - pub(crate) fn resolve_parent_class_names( |
| 1051 | + pub fn resolve_parent_class_names( |
1038 | 1052 | classes: &mut [ClassInfo], |
1039 | 1053 | use_map: &HashMap<String, String>, |
1040 | 1054 | namespace: &Option<String>, |
|
0 commit comments