Skip to content

Do not report non existent offset when it s an array creation#4204

Merged
ondrejmirtes merged 4 commits intophpstan:2.1.xfrom
VincentLanglet:fix/12447
Sep 2, 2025
Merged

Do not report non existent offset when it s an array creation#4204
ondrejmirtes merged 4 commits intophpstan:2.1.xfrom
VincentLanglet:fix/12447

Conversation

@VincentLanglet
Copy link
Copy Markdown
Contributor

@VincentLanglet VincentLanglet commented Aug 4, 2025

@VincentLanglet VincentLanglet marked this pull request as ready for review August 4, 2025 08:53
@phpstan-bot
Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes
Copy link
Copy Markdown
Member

I feel like we'd need a similar fix for Scope manipulation in NodeScopeResolver. There this situation is detected by instanceof ErrorType which sometimes fails.

Try adding assertType tests around this code.

@VincentLanglet
Copy link
Copy Markdown
Contributor Author

Try adding assertType tests around this code.

Added.

We get,

assertType('mixed', $data);
$data[] = 1;
assertType('mixed', $data);

function (): void {
	assertType('*ERROR*', $data);
	$data[] = 1;
	assertType('array{1}', $data);
};

@ondrejmirtes
Copy link
Copy Markdown
Member

We should get rid of instanceof ErrorType in NodeScopeResolver. It leads to these problems: https://phpstan.org/r/a2ab0fbe-4741-4ab3-8d8e-51d9d29a91ac

@ondrejmirtes
Copy link
Copy Markdown
Member

And regarding:

We get,

That's perfect! 👍

@VincentLanglet
Copy link
Copy Markdown
Contributor Author

VincentLanglet commented Aug 4, 2025

We should get rid of instanceof ErrorType in NodeScopeResolver. It leads to these problems: phpstan.org/r/a2ab0fbe-4741-4ab3-8d8e-51d9d29a91ac

I get

$a = $foo->doFoo();
		assertType('*ERROR*', $a);
		$a[] = 5;
		assertType('mixed', $a);

now

@ondrejmirtes
Copy link
Copy Markdown
Member

Look at the issue bot, this also fixes phpstan/phpstan#7286 (your issue) and also maybe phpstan/phpstan#3803. Please add regression tests for them.

@VincentLanglet
Copy link
Copy Markdown
Contributor Author

Look at the issue bot, this also fixes phpstan/phpstan#7286 (your issue) and also maybe phpstan/phpstan#3803. Please add regression tests for them.

Indeed, both are fixed. Nice, I added two non regressions tests then.

@ondrejmirtes ondrejmirtes merged commit cabe851 into phpstan:2.1.x Sep 2, 2025
449 of 454 checks passed
@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

3 participants