Skip to content

Fix 10922: array type in foreach#3029

Merged
ondrejmirtes merged 2 commits into
phpstan:1.10.xfrom
VincentLanglet:polluteScope
Apr 23, 2024
Merged

Fix 10922: array type in foreach#3029
ondrejmirtes merged 2 commits into
phpstan:1.10.xfrom
VincentLanglet:polluteScope

Conversation

@VincentLanglet

@VincentLanglet VincentLanglet commented Apr 23, 2024

Copy link
Copy Markdown
Contributor

Comment thread src/Analyser/NodeScopeResolver.php Outdated
@@ -951,7 +951,10 @@ private function processStmtNode(
]),
)));
} else {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the purpose of

if ($this->polluteScopeWithAlwaysIterableForeach) {
     $finalScope = $finalScope->mergeWith($scope->filterByTruthyValue(new BooleanOr(
	     new BinaryOp\Identical(
		     $stmt->expr,
			 new Array_([]),
	     ),
		 new FuncCall(new Name\FullyQualified('is_object'), [
			 new Arg($stmt->expr),
		 ]),
	)));
} else {
	$finalScope = $finalScope->mergeWith($scope);
}

But I soon as I make this change, the issue is solved.

I dunno

  • if it has a bad impact (I can add tests if you had some in mind)
  • if I should just remove the else part and the if condition.

@phpstan-bot

Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

Comment thread src/Analyser/NodeScopeResolver.php Outdated
public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/../../../conf/bleedingEdge.neon',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging with parent would be better (I think bleedingEdge is there already)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parent is

/**
	 * @return string[]
	 */
	public static function getAdditionalConfigFiles(): array
	{
		return [];
	}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NodeScopeResolverTest use

	public static function getAdditionalConfigFiles(): array
	{
		return [
			__DIR__ . '/../../../conf/bleedingEdge.neon',
			__DIR__ . '/typeAliases.neon',
		];
	}

I followed the same idea

@ondrejmirtes ondrejmirtes merged commit 27e2b53 into phpstan:1.10.x Apr 23, 2024
@ondrejmirtes

Copy link
Copy Markdown
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants