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

Invalid start location for class constants / properties #511

Open
czosel opened this issue Mar 21, 2020 · 7 comments
Open

Invalid start location for class constants / properties #511

czosel opened this issue Mar 21, 2020 · 7 comments
Assignees
Milestone

Comments

@czosel
Copy link
Collaborator

czosel commented Mar 21, 2020

Input:

<?php
class A
{
    const test = 1;
}

AST (excerpt):

"kind": "classconstant",
          "loc": {
            "source": "test = 1",
            "start": {
              "line": 4,
              "column": 10,
              "offset": 26
            },
            "end": {
              "line": 4,
              "column": 18,
              "offset": 34
            }
          },

I think the start column of the class constant is off, it should be around 4 instead of 10 in the example.

@czosel
Copy link
Collaborator Author

czosel commented Mar 21, 2020

The same thing happens with class properties:

<?php
class A
{
    public $test = 1;
}

AST:

"kind": "propertystatement",
          "loc": {
            "source": "$test = 1",
            "start": {
              "line": 4,
              "column": 11,
              "offset": 27
            },
            "end": {
              "line": 4,
              "column": 20,
              "offset": 36
            }
          },

@czosel czosel changed the title Invalid start location for class constants Invalid start location for class constants / properties Mar 21, 2020
@alexander-akait
Copy link
Collaborator

Yes, it is old issues 😞

@czosel
Copy link
Collaborator Author

czosel commented Mar 23, 2020

Maybe related to #208 ?

@alexander-akait
Copy link
Collaborator

Yes, i try to keep all in the one PR, but it's just my preference

@czosel
Copy link
Collaborator Author

czosel commented Mar 23, 2020

Doesn't matter as long as we get it fixed 😉

@ichiriac ichiriac self-assigned this Mar 26, 2020
@ichiriac ichiriac added this to the 3.0.0 - stable milestone Mar 26, 2020
ichiriac added a commit that referenced this issue Mar 26, 2020
@ichiriac
Copy link
Member

for const the fix is easy, but for properties / functions it's more complicated as the final / abstract / private / protected / public tokens may be eaten before creating the function or property node - one solution would be to use swapLocations on the generated and store on flags the parser position before eating modifiers tokens

@ichiriac
Copy link
Member

Hi @evilebottnawi, it would be great if you have some time that you keep working on branch #fix-issue-511 as the fix is not fully implemented.

Remains to check interfaces, traits, use alias on traits, but the principle remains the same as in the last commit

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

No branches or pull requests

3 participants