Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Comment missing in AST when in the middle of fluent call #742

Closed
ondrejmirtes opened this issue Dec 18, 2020 · 3 comments
Closed

Comment missing in AST when in the middle of fluent call #742

ondrejmirtes opened this issue Dec 18, 2020 · 3 comments

Comments

@ondrejmirtes
Copy link
Contributor

Given this code:

<?php

declare(strict_types=1);

$objectForSetter = new ObjectForSetter();
$awesomeFeature = new AwesomeFeature();
$awesomeFeature
	->setVariable($objectForSetter->getVariable()) // @phpstan-ignore-line
	->doSmth();

There's no @phpstan-ignore-line comment in the AST.

Original issue: phpstan/phpstan#4250

@ondrejmirtes
Copy link
Contributor Author

ondrejmirtes commented Dec 18, 2020

(Sorry for the doublepost, I got HTTP 404 from GitHub originally.)

@nikic
Copy link
Owner

nikic commented Dec 20, 2020

This is hard to address with the current comment mechanism, which always assigns comments to the directly following node, which doesn't exist here (-> does not start a node).

I think for phpstans purposes it might be more useful to handle this not at the AST level, but to do one iteration over the tokens ($lexer->getTokens()) upfront and handle the T_COMMENT/T_DOC_COMMENT tokens. You don't care about the node it is associated with after all. I think this shouldn't be more complicated that your current code.

@ondrejmirtes
Copy link
Contributor Author

Thank you, I'll give it a shot :)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants