Skip to content

Commit

Permalink
Allow enum class const inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Aug 16, 2024
1 parent 55a09ad commit 9956c52
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/code_info/classlike_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ pub struct ClassLikeInfo {
*/
pub required_classlikes: Vec<StrId>,

/**
* A trait can require extending classes and interfaces
*/
pub enum_class_extends: Vec<StrId>,

/**
* Parent classes
*/
Expand Down Expand Up @@ -227,6 +232,7 @@ impl ClassLikeInfo {
has_visitor_issues: false,
preserve_constructor_signature: false,
enforce_template_inheritance: false,
enum_class_extends: vec![],

direct_class_interfaces: vec![],
all_parent_classes: vec![],
Expand Down
28 changes: 28 additions & 0 deletions src/code_info_builder/classlike_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,34 @@ pub(crate) fn scan(
codebase.symbols.add_enum_class_name(class_name);

if let Some(enum_node) = &classlike_node.enum_ {
for enum_extends in &enum_node.includes {
let extend_class = get_type_from_hint(
&enum_extends.1,
None,
&TypeResolutionContext::new(),
resolved_names,
file_source.file_path,
enum_node.base.0.start_offset() as u32,
)
.unwrap()
.get_single_owned();

if let TAtomic::TReference {
name, type_params, ..
} = extend_class
{
storage.enum_class_extends.push(name);

signature_end = enum_extends.0.end_offset() as u32;

if let Some(type_params) = type_params {
storage
.template_extended_offsets
.insert(name, type_params.into_iter().map(Arc::new).collect());
}
}
}

storage.enum_type = Some(
get_type_from_hint(
&enum_node.base.1,
Expand Down
19 changes: 19 additions & 0 deletions src/file_scanner_analyzer/populator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,16 @@ fn populate_classlike_storage(
);
}

for direct_enum_extends in &storage.enum_class_extends.clone() {
populate_data_from_parent_classlike(
&mut storage,
codebase,
direct_enum_extends,
symbol_references,
safe_symbols,
);
}

for direct_parent_interface in &storage.direct_parent_interfaces.clone() {
populate_interface_data_from_parent_interface(
&mut storage,
Expand Down Expand Up @@ -693,6 +703,15 @@ fn populate_data_from_trait(
return;
};

storage.constants.extend(
trait_storage
.constants
.iter()
.filter(|(k, _)| !storage.constants.contains_key(*k))
.map(|v| (*v.0, v.1.clone()))
.collect::<FxHashMap<_, _>>(),
);

storage
.all_class_interfaces
.extend(trait_storage.direct_class_interfaces.clone());
Expand Down
7 changes: 1 addition & 6 deletions src/ttype/type_comparator/atomic_type_comparator.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
use std::{collections::BTreeMap, sync::Arc};

use crate::{
get_arrayish_params, get_value_param,
type_expander::{expand_union, TypeExpansionOptions},
wrap_atomic,
};
use crate::{get_arrayish_params, get_value_param, wrap_atomic};
use hakana_reflection_info::{
class_constant_info::ConstantInfo,
codebase_info::CodebaseInfo,
data_flow::graph::DataFlowGraph,
t_atomic::{DictKey, TAtomic},
t_union::TUnion,
};
Expand Down

0 comments on commit 9956c52

Please sign in to comment.