Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 10922: array type in foreach #3029

Merged
merged 2 commits into from
Apr 23, 2024

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Apr 23, 2024

@@ -951,7 +951,10 @@ private function processStmtNode(
]),
)));
} else {
Copy link
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
Collaborator

This pull request has been marked as ready for review.

src/Analyser/NodeScopeResolver.php Outdated Show resolved Hide resolved
public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/../../../conf/bleedingEdge.neon',
Copy link
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
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
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
442 of 443 checks passed
@ondrejmirtes
Copy link
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
3 participants