[BetterPhpDocParser] Handle parseString() got ShouldNotHappenException #5299
[BetterPhpDocParser] Handle parseString() got ShouldNotHappenException #5299TomasVotruba merged 29 commits intomasterfrom
Conversation
9064d13 to
496b80f
Compare
|
@vhenzl @ERuban please verify if this can fix #5267 , You can try with the following steps: composer config minimum-stability dev
composer config prefer-stable true
composer remove rector/rector
composer require --dev rector/rector:dev-fix-5267
# run rector process to the file affected
composer rector -- process --no-progress-bar --dry-run --debug src/RectorBug.php |
|
All checks have passed 🎉 @TomasVotruba it is ready for review. |
|
Thanks @samsonasik for looking into that, but I don't think this is correct. I had just a quick glance, but the first impression is that you are here treating symptoms instead of the disease cause. By ignoring the parsing error of a comment with Also, having a logic based on an exception named See these two my comments: #5267 (comment) and #5267 (comment). I believe the problem was introduced in #5250 which removed PhpDocInfoNodeVisitor.php and as a result, |
|
@vhenzl thank you for verify, feel free to create other PR if you have better solution ;) |
|
@vhenzl I created new commit to verify PropertyFetch by checking for its type from scope as the PropertyFetch is came from the method parameter. Please verify if that is better solution ;) |
|
rebased. |
|
All checks have passed 🎉 @TomasVotruba it is ready for review. |
|
updated with better approach with check PropertyFetch has |
|
I refactored to ensure |
|
All checks have passed 🎉 @TomasVotruba it is ready for review. |
|
Good job, @samsonasik. The problem is disappeared in my project. |
|
@TomasVotruba @samsonasik This isn't correct. Yes, it fixes the issue, but the resolved type of a property fetch is wrong. There isn't any test for // vendor/rector/rector/packages/node-type-resolver/src/NodeTypeResolver.php
public function resolve(Node $node): Type
{
$type = $this->resolveFirstType($node);
if (! $type instanceof TypeWithClassName) {
echo "<1 " . __METHOD__ . ": {$node->getType()} ({$node->name}): ".$type->describe(VerbosityLevel::cache())."\n";
return $type;
}
$type = $this->parentClassLikeTypeCorrector->correct($type);
echo "<2 " . __METHOD__ . ": {$node->getType()} ({$node->name}): ".$type->describe(VerbosityLevel::cache())."\n";
return $type;
}The original repro example isn't exactly good, so I modified it like this: // src/Abc.php
class Abc
{
public function get(string $s): string
{
return $s;
}
}
// src/Xyz.php
class Xyz
{
/**
* @var Abc
*/
public $abc;
/**
* @var string
*/
public $str;
}
// src/RectorBug.php
class RectorBug
{
public function fails(Xyz $xyz): void
{
$xyz->abc->get('xxx');
$xyz->str->xxx();
}
}Rector 0.9.10 correctly prints: Rector with this PR resolves types incorrectly and prints: |
|
@vhenzl please create PR with the failing test and fixture for that, thank you. |
|
@samsonasik See #5307 |
rectorphp/rector-src@7badba6 [PostRector] Allow remove unused use sub namespace on UnusedImportRemovingPostRector (#5299)
Fixes #5267