Skip to content

Commit

Permalink
Fix resolution of static method names
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Apr 30, 2024
1 parent 12f77a1 commit 395a8aa
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 49 deletions.
19 changes: 5 additions & 14 deletions src/analyzer/expr/call/new_analyzer.rs
Expand Up @@ -61,14 +61,14 @@ pub(crate) fn analyze(
"self" => {
let self_name = &context.function_context.calling_class.unwrap();

get_named_object(*self_name, &None)
get_named_object(*self_name, None)
}
"parent" => {
let self_name = &context.function_context.calling_class.unwrap();

let classlike_storage = codebase.classlike_infos.get(self_name).unwrap();

get_named_object(classlike_storage.direct_parent_class.unwrap(), &None)
get_named_object(classlike_storage.direct_parent_class.unwrap(), None)
}
"static" => {
let self_name = &context.function_context.calling_class.unwrap();
Expand Down Expand Up @@ -101,19 +101,10 @@ pub(crate) fn analyze(
));
};

let type_resolution_context = if let Some(id) =
context.function_context.calling_functionlike_id
{
if let Some(storage) = codebase.functionlike_infos.get(&id.to_ref()) {
&storage.type_resolution_context
} else {
&None
}
} else {
&None
};
let type_resolution_context =
statements_analyzer.get_type_resolution_context();

get_named_object(name_string, type_resolution_context)
get_named_object(name_string, Some(type_resolution_context))
}
}
} else {
Expand Down
29 changes: 16 additions & 13 deletions src/analyzer/expr/call/static_call_analyzer.rs
Expand Up @@ -56,7 +56,7 @@ pub(crate) fn analyze(

classlike_name = Some(*self_name);

get_named_object(*self_name, &None)
get_named_object(*self_name, None)
}
StrId::PARENT => {
let self_name =
Expand Down Expand Up @@ -107,21 +107,24 @@ pub(crate) fn analyze(
})
}
_ => {
classlike_name = Some(*name);
let type_resolution_context =
statements_analyzer.get_type_resolution_context();

let type_resolution_context = if let Some(id) =
context.function_context.calling_functionlike_id
{
if let Some(storage) = codebase.functionlike_infos.get(&id.to_ref()) {
&storage.type_resolution_context
} else {
&None
let lhs = get_named_object(*name, Some(type_resolution_context));

match lhs.get_single() {
TAtomic::TNamedObject { name, .. } => {
classlike_name = Some(*name);
}
TAtomic::TGenericClassname { as_type, .. } => {
if let TAtomic::TNamedObject { name, .. } = &**as_type {
classlike_name = Some(*name);
}
}
} else {
&None
};
_ => (),
}

get_named_object(*name, type_resolution_context)
lhs
}
}
} else {
Expand Down
14 changes: 2 additions & 12 deletions src/analyzer/expr/fetch/static_property_fetch_analyzer.rs
Expand Up @@ -98,20 +98,10 @@ pub(crate) fn analyze(
EFFECT_READ_PROPS,
);

let type_resolution_context = if let Some(id) = context.function_context.calling_functionlike_id
{
if let Some(storage) = codebase.functionlike_infos.get(&id.to_ref()) {
&storage.type_resolution_context
} else {
&None
}
} else {
&None
};

let type_resolution_context = statements_analyzer.get_type_resolution_context();
analysis_data.set_expr_type(
&stmt_class.1,
get_named_object(classlike_name, type_resolution_context),
get_named_object(classlike_name, Some(type_resolution_context)),
);

let prop_name = match &stmt_name {
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/expr/xml_analyzer.rs
Expand Up @@ -239,7 +239,7 @@ pub(crate) fn analyze(

analysis_data.expr_types.insert(
(pos.start_offset() as u32, pos.end_offset() as u32),
Rc::new(get_named_object(*xhp_class_name, &None)),
Rc::new(get_named_object(*xhp_class_name, None)),
);

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/stmt/try_analyzer.rs
Expand Up @@ -170,7 +170,7 @@ pub(crate) fn analyze(

let catch_var_id = &catch.1 .1 .1;

let mut catch_type = get_named_object(*catch_classlike_name, &None);
let mut catch_type = get_named_object(*catch_classlike_name, None);

catch_context.remove_descendants(
catch_var_id,
Expand Down
2 changes: 1 addition & 1 deletion src/code_info_builder/classlike_scanner.rs
Expand Up @@ -234,7 +234,7 @@ pub(crate) fn scan(
{
storage.template_extended_offsets.insert(
interface_name,
vec![Arc::new(get_named_object(*class_name, &None))],
vec![Arc::new(get_named_object(*class_name, None))],
);
} else {
storage.template_extended_offsets.insert(
Expand Down
23 changes: 17 additions & 6 deletions src/file_scanner_analyzer/populator.rs
Expand Up @@ -319,6 +319,22 @@ fn populate_functionlike_storage(
}
}

if let Some(ref mut type_resolution_context) = storage.type_resolution_context {
for (_, type_param_map) in type_resolution_context.template_type_map.iter_mut() {
for (_, v) in type_param_map {
if force_type_population || v.needs_population() {
populate_union_type(
Arc::make_mut(v),
codebase_symbols,
reference_source,
symbol_references,
force_type_population,
);
}
}
}
}

for (_, where_type) in storage.where_constraints.iter_mut() {
populate_union_type(
where_type,
Expand Down Expand Up @@ -632,12 +648,7 @@ fn populate_data_from_trait(
symbol_references: &mut SymbolReferences,
safe_symbols: &FxHashSet<StrId>,
) {
populate_classlike_storage(
trait_name,
codebase,
symbol_references,
safe_symbols,
);
populate_classlike_storage(trait_name, codebase, symbol_references, safe_symbols);

symbol_references.add_symbol_reference_to_symbol(storage.name, *trait_name, true);

Expand Down
2 changes: 1 addition & 1 deletion src/ttype/lib.rs
Expand Up @@ -118,7 +118,7 @@ pub fn get_object() -> TUnion {
#[inline]
pub fn get_named_object(
name: StrId,
type_resolution_context: &Option<TypeResolutionContext>,
type_resolution_context: Option<&TypeResolutionContext>,
) -> TUnion {
if let Some(type_resolution_context) = type_resolution_context {
if let Some(t) = type_resolution_context
Expand Down

0 comments on commit 395a8aa

Please sign in to comment.