-
Notifications
You must be signed in to change notification settings - Fork 665
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
@psalm-internal namespace check confuses class name with a namespace #8339
Comments
I found these snippets: https://psalm.dev/r/d1e3175a52<?php
namespace Component\Internal
{
class C
{
/** @psalm-internal Component\Internal */
public function __construct() {
}
}
}
namespace Component
{
use Component\Internal\C;
class Internal
{
public function getC(): C {
return new C(); // should complain about InternalMethod
}
}
}
https://psalm.dev/r/58990a724b<?php
namespace Component\Internal
{
class C
{
/** @psalm-internal Component\Internal */
public function __construct() {
}
}
}
namespace Component
{
use Component\Internal\C;
class OtherName
{
public function getC(): C {
return new C(); // complains about InternalMethod
}
}
}
|
This is a result of #8165. I'm open to ideas on how to disambiguate classes and namespaces, maybe we should have a separate Edit: When I implemented this I actually did consider this case, but I figured it would be a feature rather than a bug. I would think if you have the namespace |
I'm not sure how I feel about classes that have the same FQN as a namespace. Is it widely used? Don't we have some kind of PSR rule to forbid that? |
We use that in Psalm (check out |
@orklah why forbidding that? Personally I use it extensively when defining a class which consists of some nested objects, and then nested classes are defined in a namespace with the same name, e.g.
It's convenient to further refer to the nested classes as |
Also, following PSR recommendations is just a personal preference. Psalm itself does not follow PSR-12's code style guidelines. |
Right, I never made the connection
For the exact same reason this issue exists. It creates ambiguity and ambiguity leads to bugs :). FQN stands for Fully Qualified Name, I would expect that anything fully qualified should be specific enough not to be confused with another symbol but I guess I'm alone here 😄. |
Seems totally natural to me 🤷 The thing I'm not sure about is whether we should call the way |
It works "good enough" in the same sense |
I see those issues as fundamentally different. We may end up changing it, but I can't think of a great way to do it so far. Either we add a separate tag, in which case I think we might want a separate tag for methods as well so it's consistent, or we find a way to disambiguate classes and namespaces with the current tag, which I'm not sure how to do. |
I'm following the official Psalm documentation, which should be the source of truth:
Here the calling code is not within the namespace You could update the documentation though, if you wish to reinterpet the behavior. https://psalm.dev/docs/annotating_code/supported_annotations/#psalm-internal |
Yeah, that should have been done in #8165, sorry I missed that. I think it's better to wait now though until we figure out if we want to do anything about this issue. |
I find the new behavior more confusing though, than the currently documented one. At least it's harder to explain it. |
One option could be postfixes. E.g. |
Yeah, that's something. I'd also prefer something along the lines of the originally suggested |
https://psalm.dev/r/d1e3175a52 - should complain, but doesn't, because the class in the parent namespace is called the same as the child namespace
https://psalm.dev/r/58990a724b - works fine, because the callee class has different name than the namespace.
The text was updated successfully, but these errors were encountered: