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

Error with array references in Reconciler #8289

Closed
ohader opened this issue Jul 20, 2022 · 4 comments
Closed

Error with array references in Reconciler #8289

ohader opened this issue Jul 20, 2022 · 4 comments

Comments

@ohader
Copy link
Contributor

ohader commented Jul 20, 2022

https://psalm.dev/r/03af5df16f

Check XHR response in browser's dev console (actually it's "just" a warning, however analyzer stops)

Warning: Undefined array key "$doesNotMatter[$a]" in /var/www/vhosts/psalm.dev/httpdocs/vendor/vimeo/psalm/src/Psalm/Type/Reconciler.php on line 128
{"error":{"message":"\/vendor\/vimeo\/psalm\/src\/Psalm\/Type\/Reconciler.php: __clone method called on non-object","line_from":128,"type":"psalm_error"}}

$existing_types[$referenced] = clone $old_existing_types[$referenced];

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/03af5df16f
<?php
$a = 'a';
$b = false;

$doesNotMatter = ['a' => ['id' => 1]];
// only the reference `&` seems to matter here
// check PHP error message in XHR response
// ```
// Warning: Undefined array key "$doesNotMatter[$a]" in /var/www/vhosts/psalm.dev/httpdocs/vendor/vimeo/psalm/src/Psalm/Type/Reconciler.php on line 128
// {"error":{"message":"\/vendor\/vimeo\/psalm\/src\/Psalm\/Type\/Reconciler.php: __clone method called on non-object","line_from":128,"type":"psalm_error"}}
// ```
$reference = &$doesNotMatter[$a];

// this comparison is also involved
// interesting that `$reference` is not accessed at all
$result = ($a === 'not-a' && ($b || false));
Psalm encountered an internal error:

/vendor/vimeo/psalm/src/Psalm/Type/Reconciler.php: __clone method called on non-object

@ohader
Copy link
Contributor Author

ohader commented Jul 20, 2022

@AndrolGenhald I just created a test-case for this, feel free to reuse them from PR #8290

@AndrolGenhald
Copy link
Collaborator

I'll try to get this fixed soon, but I've given up on further improving support for arrays and objects with references, they're (imo) incredibly buggy and unintuitive: https://3v4l.org/3RncH

@ohader
Copy link
Contributor Author

ohader commented Jul 20, 2022

Incredible, I was not aware of that flaw in PHP! 😮
For the time being I think, it would be enough to encapsulate those scenarios and just not process the buggy ones.

orklah added a commit that referenced this issue Jul 21, 2022
Fix type reconciliation breaking Context::$references_in_scope (fixes #8289).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants