Skip to content

Commit

Permalink
Mark pure function effects where necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed May 3, 2024
1 parent 028bcb1 commit 7cb0ae7
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/analyzer/expr/call_analyzer.rs
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use hakana_reflection_info::code_location::HPos;
use hakana_reflection_info::issue::{Issue, IssueKind};
use hakana_reflection_info::{GenericParent, EFFECT_IMPURE, EFFECT_WRITE_PROPS};
use hakana_reflection_info::{GenericParent, EFFECT_IMPURE, EFFECT_PURE, EFFECT_WRITE_PROPS};
use hakana_str::StrId;
use hakana_type::template::standin_type_replacer::get_relevant_bounds;
use hakana_type::type_comparator::type_comparison_result::TypeComparisonResult;
Expand Down Expand Up @@ -504,7 +504,10 @@ pub(crate) fn apply_effects(
}
}
FnEffect::Pure => {
// do nothing, it's a pure function
analysis_data.expr_effects.insert(
(pos.start_offset() as u32, pos.end_offset() as u32),
EFFECT_PURE,
);
}
FnEffect::Unknown => {
// yet to be computed
Expand Down
1 change: 1 addition & 0 deletions src/analyzer/stmt_analyzer.rs
Expand Up @@ -345,6 +345,7 @@ fn detect_unused_statement_expressions(
}
}
}

if let Some(functionlike_id) = functionlike_id {
if let FunctionLikeIdentifier::Function(function_id) = functionlike_id {
let codebase = statements_analyzer.get_codebase();
Expand Down
@@ -0,0 +1 @@
ERROR: UnusedStatement - input.hack:6:5 - This statement has no effect and can be removed
15 changes: 15 additions & 0 deletions tests/unused/UnusedExpression/unusedPureMethodCall/input.hack
@@ -0,0 +1,15 @@
class UnusedMethodClass {
public function getId()[]: int {
return 5;
}

public function doWork(): string {
return '';
}
}

function foo(): void {
$c = new UnusedMethodClass();
$c->getId();
$c->doWork();
}
@@ -0,0 +1 @@
ERROR: UnusedStatement - input.hack:13:5 - This statement has no effect and can be removed

0 comments on commit 7cb0ae7

Please sign in to comment.