Skip to content

Commit 4d06e6b

Browse files
committed
Implement implicitly inherited
1 parent cd1ffac commit 4d06e6b

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

example.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ enum Priority: int
8888
case High = 3;
8989
}
9090

91+
enum Mode
92+
{
93+
case Automatic;
94+
case Manual;
95+
}
96+
9197
// ─── Base / Parent Class ────────────────────────────────────────────────────
9298

9399
/**

src/parser.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use std::collections::HashMap;
88

99
use bumpalo::Bump;
10+
use mago_span::HasSpan;
1011
use mago_syntax::ast::*;
1112
use mago_syntax::parser::parse_file_content;
1213

@@ -683,9 +684,28 @@ impl Backend {
683684
Statement::Enum(enum_def) => {
684685
let enum_name = enum_def.name.value.to_string();
685686

686-
let (mut methods, mut properties, constants, used_traits) =
687+
let (mut methods, mut properties, constants, mut used_traits) =
687688
Self::extract_class_like_members(enum_def.members.iter(), doc_ctx);
688689

690+
// Determine if the enum is a BackedEnum or UnitEnum
691+
let implicit_interface = if let Some(backing) = &enum_def.backing_type_hint {
692+
if let Some(ctx) = doc_ctx {
693+
let range = backing.hint.span().to_range_usize();
694+
let backing_str = &ctx.content[range];
695+
match backing_str {
696+
"int" | "string" => "BackedEnum",
697+
_ => "UnitEnum",
698+
}
699+
} else {
700+
"UnitEnum"
701+
}
702+
} else {
703+
"UnitEnum"
704+
};
705+
706+
// Add the implicit interface to used_traits
707+
used_traits.push(implicit_interface.to_string());
708+
689709
// Extract @property, @method, and @mixin tags from the enum-level docblock.
690710
let mut mixins = Vec::new();
691711
if let Some(ctx) = doc_ctx

0 commit comments

Comments
 (0)