Skip to content

[TypeDeclaration] Refactor UnionTypeMapper::narrowBoolType() to allow bool|int|false converted to bool|int#3685

Merged
samsonasik merged 9 commits intomainfrom
refactor-uniontype-narrow-bool
Apr 25, 2023
Merged

[TypeDeclaration] Refactor UnionTypeMapper::narrowBoolType() to allow bool|int|false converted to bool|int#3685
samsonasik merged 9 commits intomainfrom
refactor-uniontype-narrow-bool

Conversation

@samsonasik
Copy link
Copy Markdown
Member

@internalsystemerror @eugeniya-v I am back and forth checking it so we have functionality to keep working, while prevent the infinite loop, and finally seems I am succeed :)

@samsonasik
Copy link
Copy Markdown
Member Author

samsonasik commented Apr 25, 2023

Or not yet, the following code:

class NarrowBoolFalse3
{
    /**
     * @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;
    }
}

Ref https://phpstan.org/r/abf31a54-b4dc-49a7-9585-d018ee2bc526

still changed to:

-public function go($param)
+public function go(bool|int|false $param): bool|int

which wrong ..., ref https://3v4l.org/KcCIk

@samsonasik samsonasik marked this pull request as draft April 25, 2023 19:24
@samsonasik samsonasik marked this pull request as ready for review April 25, 2023 19:40
@samsonasik
Copy link
Copy Markdown
Member Author

Fixed 🎉

@samsonasik
Copy link
Copy Markdown
Member Author

All checks have passed 🎉 @TomasVotruba I think it is ready.

@samsonasik
Copy link
Copy Markdown
Member Author

@TomasVotruba I am merging it ;)

@samsonasik samsonasik merged commit 92d38cf into main Apr 25, 2023
@samsonasik samsonasik deleted the refactor-uniontype-narrow-bool branch April 25, 2023 20:57
samsonasik added a commit that referenced this pull request May 8, 2023
… bool|int|false converted to bool|int (#3685)

* [TypeDeclaration] Refactor UnionTypeMapper::narrowBoolType()

* more fixture

* Fixed 🎉

* already unique $phpParserUnionType->types in previous process

* early no type check

* Revert early no type check

This reverts commit f468270.

* skip array reverse index on php 7.x

* clean up

* clean up
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.

1 participant