nikic / PHP-Parser

A PHP parser written in PHP
BSD 3-Clause "New" or "Revised" License
17.04k stars 1.1k forks source link

Warning message on PHP files consisting of only comments #589

Closed fitztrev closed 5 years ago

fitztrev commented 5 years ago

I'm using rectorphp/rector and when I run the following command, I get a warning message when it found a PHP file where the contents were only comments.

$ ./vendor/bin/rector process app --level laravel58

Contents of app/Test.php:

<?php

// A single-line comment

Output:

PHP Warning:  assert(): assert($itemStartPos >= 0 && $itemEndPos >= 0) failed in
vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php on line 753
fitztrev commented 5 years ago

It seems the issue is only on PHP 7.2. Just tried on 7.3 and the warning is not there.

fitztrev commented 5 years ago

Had to do with PHP zend.assertions config. See rectorphp/rector#1157 for more details.

TomasVotruba commented 5 years ago

It still should pass even with assertions on. I'll try to investigate, what is causing this.

Probably some attribute copying

fitztrev commented 5 years ago

Re-opening because I was able to generate some steps to reproduce and a failing test here: https://github.com/rectorphp/rector/pull/1284

I'll leave it to this project's maintainers to determine how/if they would like to handle. Thanks

nikic commented 5 years ago

Can repro. I think that the end attributes on the nop statement are completely missing in this case, which is why we get a -1 token end pos.

fitztrev commented 5 years ago

I just attempted a fix in #601. This was my first dive into this code so it could definitely use a review. Could either of you take a look and let me know? @nikic @TomasVotruba