You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Diagnostics: iterable wrongly identified as "non-existing class" #1101
I think that's the reason we got the error, the stub consider it (or the use we made of the stubs) as a class.
I remember that at some point phpactor would add some use iterable; when implementing contracts and stuff like that, but I can't reproduce so that must have been fixed since.
iterable is part of the Jetbrains PHPStorm stubs. The problem is that these are not currently indexed and the diagnostics use the indexer exclusively (it would be too slow otherwise).
So the solution is to ensure that the stubs are indexed.
Apparently the option to configure stubs this has been implemented here.
So it might be as simple as including vendor/jetbrains/phpstorm-stubs directory by default here
Does it make sense to put the stubs in the index though ?
Would it not make more sense to query the index, as it is done currently, and if not found in the index then check the stub ?
Or aggregate the result of the index with the content of the stubs in some way.
No matter all that, I try your idea and it didn't worked.
I defined the parameter with %applicaiton_root%/vendor/jetbrains/phpstorm-strubs and rebuild my index.
I still got the error, then I tried to take a quick look at how the parameter was used and it seems like it will only be used to define glob patterns that must be match in order for a file to be returned by the FilesystemFileListProvider.
But the Filesystem created for the index, take a SimpleFileListeProvider which only provide the files from the project root.
So I'm not sure if I didn't understood how it works or if the PARAM_STUB_PATHS is not used properly...
iterable is resolved to being in the current namespace, so when we arrive to the IndexerClassSourceLocator or no matter which one actually it fails.
So either we consider the pseudo type iterable like a specific case because it's actually not a QualifiedName and we treat it like self and others.
Or we have to change the TolerantQualifiedNameResolver (if another PR is validated it will be used) to not resolve iterable to the current namespace.
Or even both, the check is done in both the name resolver and the filter method.
I also need to investigate to check why we don't have the same issue with object...
object is not considered a QualifiedName by the parser if I understood correctly what was going on.
But I don't see what you mean by updating WR, for me this is what is happening (ignoring functions and constant cases):
We use Toleran Parser (TP) to retrieve all nodes of type QualifiedName
We resolve the name with TP
If the resolved name is static, self or parent we consider it OK
If the name was unresolved by TP it's resolved as being in the current namespace
We check that the resolved name is found with the Reflector (StubSourceLocator, IndexerClassSourceLocator, etc.)
So the only time WR is involved is at stage 5. which is already too late because TP would have resolved the name to Current\Namespace\iterable at stage 1.
Therfore what needs to be fixed is the name resolution, we could use the TolerantQualifiedNameResolver and update it to resolve iterable to iterable or even \iterable.
That would fix the issue and I think it our best option since it means that we would have a "correct" name resolution anywhere for iterable.
But I still don't get why TR consider a pseudo-type as a qualified name ><
I started to work on the TolerantParser, the changes are quite easy, but the implications of returning a token instead of a node might slow things down.
There already was an issue about that, since 2017... microsoft/tolerant-php-parser#348
in the meantime one way forward might be to add a test on WR and fix it there.
How do you see that exactly ?
You want to ignore the namespace if it ends by iterable in the StubSourceLocator so that it would recognize it ?
This would be valid right now but in PHP 8 we will be able to use reserved keyword in the namespaces so it won't work.
I will prepare a PR with a fix in the TolerantQualifiedNameResolver because it makes more sens to me and that would allow me to not have those errors locally.
I will update the PR once I understand how you want to solve this in WR.
I just realized that the TolerantQualifiedNameResolver is in the WR package ><
I guess that explains why I didn't get why you were talking about fixing it WR 😄
Activity
camilledejoye commentedon Oct 11, 2020
I think that's the reason we got the error, the stub consider it (or the use we made of the stubs) as a class.
I remember that at some point phpactor would add some
use iterable;when implementing contracts and stuff like that, but I can't reproduce so that must have been fixed since.Do you know what tool generate this error ?
dantleech commentedon Oct 11, 2020
Phpactor generates this error. The reason is because it's searching for the name using the index, but the stubs are not indexed.
camilledejoye commentedon Oct 17, 2020
What about excluding this case like it's done here: https://github.com/phpactor/code-transform/blob/41071cee6da50937e68e8a6391d03719e2e649c7/lib/Adapter/WorseReflection/Helper/WorseUnresolvableClassNameFinder.php#L83
Something like:
Since
iterableis a reserved keyword I think it's OK to handle it this way.If it's OK for you I will do the PR, it's a really quick fix and adding a test is just as simple.
dantleech commentedon Oct 17, 2020
iterableis part of the Jetbrains PHPStorm stubs. The problem is that these are not currently indexed and the diagnostics use the indexer exclusively (it would be too slow otherwise).So the solution is to ensure that the stubs are indexed.
Apparently the option to configure stubs this has been implemented here.
So it might be as simple as including
vendor/jetbrains/phpstorm-stubsdirectory by default herecamilledejoye commentedon Oct 17, 2020
Does it make sense to put the stubs in the index though ?
Would it not make more sense to query the index, as it is done currently, and if not found in the index then check the stub ?
Or aggregate the result of the index with the content of the stubs in some way.
No matter all that, I try your idea and it didn't worked.
I defined the parameter with
%applicaiton_root%/vendor/jetbrains/phpstorm-strubsand rebuild my index.I still got the error, then I tried to take a quick look at how the parameter was used and it seems like it will only be used to define glob patterns that must be match in order for a file to be returned by the
FilesystemFileListProvider.But the
Filesystemcreated for the index, take aSimpleFileListeProviderwhich only provide the files from the project root.So I'm not sure if I didn't understood how it works or if the
PARAM_STUB_PATHSis not used properly...camilledejoye commentedon Nov 1, 2020
There is some progress :D

iterableis resolved to being in the current namespace, so when we arrive to theIndexerClassSourceLocatoror no matter which one actually it fails.So either we consider the pseudo type
iterablelike a specific case because it's actually not aQualifiedNameand we treat it likeselfand others.Or we have to change the
TolerantQualifiedNameResolver(if another PR is validated it will be used) to not resolveiterableto the current namespace.Or even both, the check is done in both the name resolver and the filter method.
I also need to investigate to check why we don't have the same issue with
object...dantleech commentedon Nov 1, 2020
"Object" is specialed case in WorseReflection, probably enough to update WR to include iterable as a reserved name too.
camilledejoye commentedon Nov 1, 2020
objectis not considered aQualifiedNameby the parser if I understood correctly what was going on.But I don't see what you mean by updating WR, for me this is what is happening (ignoring functions and constant cases):
QualifiedNamestatic,selforparentwe consider it OKReflector(StubSourceLocator,IndexerClassSourceLocator, etc.)So the only time WR is involved is at stage
5.which is already too late because TP would have resolved the name toCurrent\Namespace\iterableat stage1.Therfore what needs to be fixed is the name resolution, we could use the
TolerantQualifiedNameResolverand update it to resolveiterabletoiterableor even\iterable.That would fix the issue and I think it our best option since it means that we would have a "correct" name resolution anywhere for
iterable.But I still don't get why TR consider a pseudo-type as a qualified name ><
dantleech commentedon Nov 2, 2020
Probably worth submitting a PR to TolerantParser, in the meantime one way forward might be to add a test on WR and fix it there.
camilledejoye commentedon Nov 2, 2020
I started to work on the TolerantParser, the changes are quite easy, but the implications of returning a token instead of a node might slow things down.
There already was an issue about that, since 2017...
microsoft/tolerant-php-parser#348
camilledejoye commentedon Nov 7, 2020
How do you see that exactly ?
You want to ignore the namespace if it ends by
iterablein theStubSourceLocatorso that it would recognize it ?This would be valid right now but in PHP 8 we will be able to use reserved keyword in the namespaces so it won't work.
I will prepare a PR with a fix in the
TolerantQualifiedNameResolverbecause it makes more sens to me and that would allow me to not have those errors locally.I will update the PR once I understand how you want to solve this in WR.
I just realized that the
TolerantQualifiedNameResolveris in the WR package ><I guess that explains why I didn't get why you were talking about fixing it WR 😄
dantleech commentedon Nov 7, 2020
Just had a closer look, maybe simply adding it here with
self,parentetc. ?https://github.com/phpactor/code-transform/blob/5a3df8a9c9d9bffe0478a37891b534027c2982dc/lib/Adapter/WorseReflection/Helper/WorseUnresolvableClassNameFinder.php#L83-L85
camilledejoye commentedon Nov 7, 2020
In the PR I did that but in the
TolerantQualifiedNameResolver, this way we will benefit from it in multiple places.dantleech commentedon Nov 7, 2020
ok, makes sense I think 👍
Updated composer
Master 17 (#1203)