Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
klimick committed Aug 15, 2023
1 parent 1539518 commit 10330e9
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 1,401 deletions.
8 changes: 0 additions & 8 deletions psalm-baseline.xml
Expand Up @@ -374,14 +374,6 @@
<code><![CDATA[$array->properties[0]]]></code>
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php">
<LessSpecificReturnStatement>
<code>$callable</code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType>
<code>TCallable|TClosure|null</code>
</MoreSpecificReturnType>
</file>
<file src="src/Psalm/Internal/Type/SimpleAssertionReconciler.php">
<PossiblyUndefinedIntArrayOffset>
<code><![CDATA[$array_atomic_type->properties[0]]]></code>
Expand Down
Expand Up @@ -898,7 +898,7 @@ public static function analyzeAssignmentRef(
PhpParser\Node\Expr\AssignRef $stmt,
Context $context
): bool {
ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context, false, null, false, null, true);
ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context, false, null, false, true);

$lhs_var_id = ExpressionIdentifier::getExtendedVarId(
$stmt->var,
Expand Down
Expand Up @@ -195,19 +195,7 @@ public static function analyze(
$toggled_class_exists = true;
}

$high_order_template_result = null;
$high_order_callable_info = $param
? HighOrderFunctionArgHandler::getCallableArgInfo($context, $arg->value, $statements_analyzer, $param)
: null;

if ($param && $high_order_callable_info) {
$high_order_template_result = HighOrderFunctionArgHandler::remapLowerBounds(
$statements_analyzer,
$template_result ?? new TemplateResult([], []),
$high_order_callable_info,
$param->type ?? Type::getMixed(),
);
} elseif (($arg->value instanceof PhpParser\Node\Expr\Closure
if (($arg->value instanceof PhpParser\Node\Expr\Closure
|| $arg->value instanceof PhpParser\Node\Expr\ArrowFunction)
&& $param
&& !$arg->value->getDocComment()
Expand All @@ -227,32 +215,14 @@ public static function analyze(
$was_inside_call = $context->inside_call;
$context->inside_call = true;

if (ExpressionAnalyzer::analyze(
$statements_analyzer,
$arg->value,
$context,
false,
null,
false,
$high_order_template_result,
) === false) {
if (ExpressionAnalyzer::analyze($statements_analyzer, $arg->value, $context) === false) {
$context->inside_call = $was_inside_call;

return false;
}

$context->inside_call = $was_inside_call;

if ($high_order_callable_info && $high_order_template_result) {
HighOrderFunctionArgHandler::enhanceCallableArgType(
$context,
$arg->value,
$statements_analyzer,
$high_order_callable_info,
$high_order_template_result,
);
}

if (($argument_offset === 0 && $method_id === 'array_filter' && count($args) === 2)
|| ($argument_offset > 0 && $method_id === 'array_map' && count($args) >= 2)
) {
Expand Down
Expand Up @@ -83,8 +83,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
public static function analyze(
StatementsAnalyzer $statements_analyzer,
PhpParser\Node\Expr\FuncCall $stmt,
Context $context,
?TemplateResult $template_result = null
Context $context
): bool {
$function_name = $stmt->name;

Expand Down Expand Up @@ -167,13 +166,11 @@ public static function analyze(
$set_inside_conditional = true;
}

if (!$template_result) {
$template_result = new TemplateResult([], []);
}

if (!$is_first_class_callable) {
$template_result = null;

if (isset($function_call_info->function_storage->template_types)) {
$template_result->template_types += $function_call_info->function_storage->template_types ?: [];
$template_result = new TemplateResult($function_call_info->function_storage->template_types ?: [], []);
}

ArgumentsAnalyzer::analyze(
Expand Down Expand Up @@ -209,8 +206,6 @@ public static function analyze(
}
}

$already_inferred_lower_bounds = $template_result->lower_bounds;

$template_result = new TemplateResult([], []);

// do this here to allow closure param checks
Expand All @@ -235,11 +230,6 @@ public static function analyze(
$function_call_info->function_id,
);

$template_result->lower_bounds = array_merge(
$template_result->lower_bounds,
$already_inferred_lower_bounds,
);

if ($function_name instanceof PhpParser\Node\Name && $function_call_info->function_id) {
$stmt_type = FunctionCallReturnTypeFetcher::fetch(
$statements_analyzer,
Expand Down

0 comments on commit 10330e9

Please sign in to comment.