Skip to content

Commit

Permalink
Simplify some code
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Aug 19, 2024
1 parent e543430 commit a28879a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/code_info/codebase_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl CodebaseInfo {
}]))
} else if let Some(constant_storage) = classlike_storage.constants.get(const_name) {
if matches!(classlike_storage.kind, SymbolKind::EnumClass) {
return constant_storage.provided_type.as_ref().map(|t| t.clone());
return constant_storage.provided_type.clone();
} else if let Some(provided_type) = &constant_storage.provided_type {
if provided_type.types.iter().all(|v| v.is_boring_scalar()) && !is_this {
if let Some(inferred_type) = &constant_storage.inferred_type {
Expand Down
28 changes: 11 additions & 17 deletions src/ttype/type_comparator/scalar_type_comparator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,12 @@ pub fn is_contained_by(
if let TAtomic::TLiteralString { value: input_value } = input_type_part {
if let Some(c) = codebase.classlike_infos.get(container_name) {
for (_, const_storage) in &c.constants {
if let Some(inferred_enum_type) = &const_storage.inferred_type {
if let TAtomic::TLiteralString {
value: inferred_value,
} = inferred_enum_type
{
if inferred_value == input_value {
return true;
}
if let Some(TAtomic::TLiteralString {
value: inferred_value,
}) = &const_storage.inferred_type
{
if inferred_value == input_value {
return true;
}
}
}
Expand Down Expand Up @@ -247,16 +245,12 @@ pub fn is_contained_by(
// check if a string matches an enum case
if let TAtomic::TLiteralString { value: input_value } = input_type_part {
if let Some(c) = codebase.classlike_infos.get(container_name) {
if let Some(inferred_enum_type) =
&c.constants.get(member_name).unwrap().inferred_type
if let Some(TAtomic::TLiteralString {
value: inferred_value,
}) = &c.constants.get(member_name).unwrap().inferred_type
{
if let TAtomic::TLiteralString {
value: inferred_value,
} = inferred_enum_type
{
if inferred_value == input_value {
return true;
}
if inferred_value == input_value {
return true;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ttype/type_expander.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{mem, sync::Arc};
use std::sync::Arc;

use hakana_reflection_info::{
classlike_info::ClassConstantType,
Expand Down Expand Up @@ -276,7 +276,7 @@ fn expand_atomic(
..
} = return_type_part
{
if let None = constraint_type {
if constraint_type.is_none() {
if let Some(classlike_storage) = codebase.classlike_infos.get(enum_name) {
*constraint_type = classlike_storage.enum_constraint.clone();
}
Expand Down

0 comments on commit a28879a

Please sign in to comment.