[TypeDeclaration] Handle regression multiple params no longer working on AddMethodCallBasedStrictParamTypeRector#3681
Conversation
… on AddMethodCallBasedStrictParamTypeRector
|
Call: $this->phpStanStaticTypeMapper->mapToPhpParserNode($unionType, $typeKind);On union type narrow bool seems was the source why cause infinite loop Let's try... |
| } | ||
|
|
||
| return $this->phpStanStaticTypeMapper->mapToPhpParserNode($unionType, $typeKind); | ||
| return null; |
There was a problem hiding this comment.
this seems cause error test:
There was 1 failure:
1) Rector\Tests\Php80\Rector\FunctionLike\UnionTypesRector\UnionTypesRectorTest::test with data set #23
Failed on fixture file "narrow_bool_false2.php.inc"
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
class NarrowBoolFalse2
{
- public function go(bool|int $param): bool|int
+ /**
+ * @param bool|int|false $param
+ * @return bool|int|false
+ */
+ public function go($param)I will check.
There was a problem hiding this comment.
Let's check that it has bool type before try to apply narrow bool 3199d38
There was a problem hiding this comment.
skipping re-map on union type is safer, see comment #3681 (comment)
|
@TomasVotruba while this bool type is working 3199d38, is working, I think re-check by $this->phpStanStaticTypeMapper->mapToPhpParserNode($unionType, $typeKind);is still dangerous for passing union type in union type mapper, as that kind of usage can be vary in multiple types with same sub, eg: add IntegerRangeType, I am going to just skip when doctype types count is not equal with union type node as this can happen again. like this : class SkipNarrowBoolFalseAnotherType
{
/**
* @param bool|int|false|int<0, max> $param
* @return bool|int|false
*/
public function go($param)
{
if (rand(0, 1)) {
return rand(0, 1) ? true : false;
}
return 1;
}
}got type again https://3v4l.org/jfN4m so: will be skipped, see b3ac267 |
|
All checks have passed 🎉 @TomasVotruba I am merging it ;) |
|
@eugeniya-v FYI, see :
|
… on AddMethodCallBasedStrictParamTypeRector (#3681) * [TypeDeclaration] Handle regression multiple params no longer working on AddMethodCallBasedStrictParamTypeRector * rollback tweak * try fixing * try with check has bool type * skip narrow bool|false|<OtherTypeHere>
@internalsystemerror this is I try to cover regression that happen when dealing with infinite loop on PR:
which multiple params which one of them is Union Type no longer working now.