Skip to content

Don't remember types after impure assignments#5514

Closed
staabm wants to merge 15 commits intophpstan:2.1.xfrom
staabm:no-impre
Closed

Don't remember types after impure assignments#5514
staabm wants to merge 15 commits intophpstan:2.1.xfrom
staabm:no-impre

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Apr 23, 2026

Allow remembering results of assignments with callables (conditional expressions), when the call is pure.

closes phpstan/phpstan#9455
closes phpstan/phpstan#5207

@staabm staabm force-pushed the no-impre branch 4 times, most recently from a84fa7c to 7f91cb0 Compare April 23, 2026 18:00
@staabm staabm marked this pull request as ready for review April 24, 2026 10:32
@phpstan-bot
Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

Comment thread tests/PHPStan/Analyser/nsrt/bug-9455.php
|| $expr instanceof Expr\StaticCall
)
) {
if (!$this->rememberPossiblyImpureFunctionValues) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure to understand the logic here.

If we rememberPossiblyImpureFunctionValues: false, you automatically continue.
But what if rememberPossiblyImpureFunctionValues is false BUT the function has @phpstan-pure ? We should not continue no ?

Copy link
Copy Markdown
Contributor Author

@staabm staabm Apr 24, 2026

Choose a reason for hiding this comment

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

my thinking is:
the logic we have here depends on impure points, which only can exist or not. we cannot reflect a "maybe has impure point" situation.

thats why I allow narrowing using function/method/static-calls in assignments only when rememberPossiblyImpureFunctionValues=true to be defensive.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When rememberPossiblyImpureFunctionValues=true and the method is maybe impure, seems like we're calling

$scope->assignExpression(new PossiblyImpureCallExpr

not sure if it helps.

Another idea:
Couldn't we add manually an ImpurePoint for non Pure method when rememberPossiblyImpureFunctionValues=false ?

@ondrejmirtes
Copy link
Copy Markdown
Member

Competing PR: #5528

I'll let you decide which one you like more. I'm also looking forward to issue-bot results.

@ondrejmirtes
Copy link
Copy Markdown
Member

Why isn't issue-bot reporting any changes for this PR? I'd understand if there was already a comment changing to +No errors but at least in case of phpstan/phpstan#9455 there isn't.

@ondrejmirtes
Copy link
Copy Markdown
Member

In case of my PR it is reporting changes: https://github.com/phpstan/phpstan-src/actions/runs/24893411085

@staabm staabm closed this Apr 24, 2026
@staabm staabm deleted the no-impre branch April 24, 2026 15:04
@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Apr 24, 2026

It was your idea in the end and it seems I did it wrong.

Lets merge the working one than :-)

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.

4 participants