Skip to content

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Oct 30, 2024

@ruudk
Copy link
Contributor

ruudk commented Oct 30, 2024

Thanks so much @staabm. I just tested this on TwigStan and it solves the problem. 🎉

This was a major blocker, as proper analysis of templates after such immediately involved callable became impossible.

It would be really great if this can make it in a last 1.12 release 🙏

$this->inFuncCall
&& $node instanceof Node\Expr\Closure
) {
$node->setAttribute(self::ATTRIBUTE_NAME, true);
Copy link
Member

Choose a reason for hiding this comment

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

This would lead to a lot of false positives. You only want to tag this if in $node->name, but right now the visitor is tagging args too.

Just check $node->name inside $node instanceof Node\Expr\FuncCall.

@staabm
Copy link
Contributor Author

staabm commented Oct 30, 2024

retargeted for 1.12 in #3593

assertType('array{date: DateTime, id: 1}', $c);

$x = (function() use (&$c) {
assertType("array{date: DateTime, id: 1, name?: 'ruud'}", $c);
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is wrong, see phpstan/phpstan#11945

Copy link
Contributor

Choose a reason for hiding this comment

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

My reasoning is, that since this function is invoked immediately, it should be treated as the same code as normally, without the function.

return 'x';
})();

assertType("array{date: DateTime, id: 1, name?: 'ruud'}", $c);
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is wrong, see phpstan/phpstan#11945

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.

Unexpected behavior when modifying a passed-by-reference variable in an immediately invoked anonymous function; caused by generalization of types

3 participants