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

[PHPStan] Run PHPStan rich parser in tests to know the types + process code with tolerant parses on 1st run #1790

Merged
merged 2 commits into from Feb 9, 2022

Conversation

TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Feb 9, 2022

Mirror to fix in PHPStan phpstan/phpstan-src@433511a

Ref rectorphp/rector#6970

@TomasVotruba TomasVotruba changed the title tv use simple parser 2 [Parser] Run PHPStan rich parser in tests to know the types + process code wtih tolerant parse on 1st run Feb 9, 2022
@TomasVotruba TomasVotruba force-pushed the tv-use-simple-parser-2 branch 2 times, most recently from 56a129d to f364011 Compare February 9, 2022 08:53
@TomasVotruba TomasVotruba changed the title [Parser] Run PHPStan rich parser in tests to know the types + process code wtih tolerant parse on 1st run [Parser] Run PHPStan rich parser in tests to know the types + process code with tolerant parses on 1st run Feb 9, 2022
@TomasVotruba TomasVotruba changed the title [Parser] Run PHPStan rich parser in tests to know the types + process code with tolerant parses on 1st run [PHPStan] Run PHPStan rich parser in tests to know the types + process code with tolerant parses on 1st run Feb 9, 2022
@TomasVotruba TomasVotruba enabled auto-merge (squash) February 9, 2022 09:06
@TomasVotruba TomasVotruba merged commit e9fb346 into main Feb 9, 2022
@TomasVotruba TomasVotruba deleted the tv-use-simple-parser-2 branch February 9, 2022 09:10
@samsonasik
Copy link
Member

@TomasVotruba it seems cause error on downgrade process

@TomasVotruba
Copy link
Member Author

I see 👍

@TomasVotruba
Copy link
Member Author

TomasVotruba commented Feb 9, 2022

I'm exploring it and there is infinite loop.
When I exclude the DowngradeJsonDecodeNullAssociativeArgRector the downgrade continues well.

The file it fail on is: vendor/clue/ndjson-react/src/Decoder.php

bin/rector p vendor/clue/ndjson-react/src/Decoder.php -c build/config/config-downgrade.php -n --clear-cache --debug

@samsonasik
Copy link
Member

samsonasik commented Feb 9, 2022

I tried rollback config/phpstan/parser.neon locally and it works again for this by this PR #1789

# see original config.neon in phpstan.neon - https://github.com/phpstan/phpstan-src/blob/386eb913abb6ac05886c5642fd48b5d99db66a20/conf/config.neon#L1582
# this file overrides definitions from the config above
services:
    defaultAnalysisParser:
        factory: @pathRoutingParser
        arguments!: []

    cachedRectorParser:
        class: PHPStan\Parser\CachedParser
        arguments:
            originalParser: @rectorParser
            cachedNodesByStringCountMax: %cache.nodesByStringCountMax%
        autowired: false

    cachedRectorSimpleParser:
        class: PHPStan\Parser\CachedParser
        arguments:
            originalParser: @rectorSimpleParser
            cachedNodesByStringCountMax: %cache.nodesByStringCountMax%
        autowired: false

    pathRoutingParser:
        class: PHPStan\Parser\PathRoutingParser
        arguments:
            currentPhpVersionRichParser: @cachedRectorParser
            currentPhpVersionSimpleParser: @cachedRectorSimpleParser
            php8Parser: @php8Parser
        autowired: false

    rectorParser:
        class: PHPStan\Parser\RichParser
        arguments:
            parser: @currentPhpVersionPhpParser
            lexer: @currentPhpVersionLexer
        autowired: no

    rectorSimpleParser:
        class: PHPStan\Parser\SimpleParser
        arguments:
            parser: @currentPhpVersionPhpParser

@TomasVotruba
Copy link
Member Author

That only hides the bug. There is infinite loop with if condition.

This is the reproducer:

vendor/bin/phpunit rules-tests/DowngradePhp72/Rector/FuncCall/DowngradeJsonDecodeNullAssociativeArgRector/DowngradeJsonDecodeNullAssociativeArgRectorTest.php --filter test#3

@samsonasik
Copy link
Member

I can't reproduce it:

 vendor/bin/phpunit rules-tests/DowngradePhp72/Rector/FuncCall/DowngradeJsonDecodeNullAssociativeArgRector/DowngradeJsonDecodeNullAssociativeArgRectorTest.php --filter test#3
PHPUnit 9.5.13 by Sebastian Bergmann and contributors.

.                                                                   1 / 1 (100%)

Time: 00:00.973, Memory: 82.50 MB

OK (1 test, 2 assertions)

and for already transformed, there is already test for it:

https://github.com/rectorphp/rector-src/blob/main/rules-tests/DowngradePhp72/Rector/FuncCall/DowngradeJsonDecodeNullAssociativeArgRector/Fixture/skip_possibly_null_already_transformed.php.inc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants