Fix lost file comment when it precedes declare(strict_types=1)#182
Open
xHeaven wants to merge 1 commit intonette:masterfrom
Open
Fix lost file comment when it precedes declare(strict_types=1)#182xHeaven wants to merge 1 commit intonette:masterfrom
xHeaven wants to merge 1 commit intonette:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extractor::extractAll()fails to extract the file-level doc comment when it appears beforedeclare(strict_types=1). This meansPhpFile::fromCode()silently drops the comment during a print-then-reparse round-trip.We discovered it in tempest/framework where our
generationpackage round-trips throughfromCode().The
PsrPrinter(andPrinter) places the file comment before the declare statement:But
extractAll()(changed here) skips theDeclare_node and only checks the next statement for a doc comment. Since the PHP parser attaches the comment to theDeclare_node it precedes, the comment is never found.The added tests in the above commit also only cover cases where the comment comes after a singleline declare, not before it.
Quick reproduction:
I've added a regression test as well to cover this case.