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

Inline comment belong to the next line #791

Open
glowdan opened this issue Jun 24, 2021 · 2 comments
Open

Inline comment belong to the next line #791

glowdan opened this issue Jun 24, 2021 · 2 comments

Comments

@glowdan
Copy link

glowdan commented Jun 24, 2021

When I parse the statements with comments. I saw something strange.

In my opinion, the inline comment belong to the code of the same line code.
but I see it is belong to the next line code now, after I tested for several times.

Here is the codes.

<?php
function commentLine() {
     $i=0;//comment $i=0
     $i=1; 
}

But when i got the parsed ast, I noticed the comment belong to the next line of "$i=1":

<?php
function commentLine() {
    $i=0;
    //comment $i=0
    $i=1;
}

Here are the diffrent examples.

<?php
function commentLine() {
     $i=0;//this comment should belong  to "$i=0", but it is "$i=1";
     $i=1;

    //this comment belong to below statement
    $i=2;

    //this comment belong to an Nop
}
@glowdan
Copy link
Author

glowdan commented Jul 9, 2021

If codes like this:

$a = [
            "k1" => "v1", //v1-comment
        ];

The comment "v1-comment" is missing.

If codes like this:

$a = [
            "v1" => "k1", //v1-comment
            "v2" => "k2", //v2-comment
        ];

The comment "v1-comment" is belong to v2 attribute. And v2-comment is missing.

@nikic So, this is a bug?

@glowdan glowdan changed the title Inline comment belong to the statement at same line. Inline comment belong to the next line Jul 9, 2021
@ondrejmirtes
Copy link
Contributor

See: #742

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

No branches or pull requests

2 participants