Bug 373416 - Classes not recognized when using absolute namespace name
Summary: Classes not recognized when using absolute namespace name
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: PHP (other bugs)
Version First Reported In: 5.0.3
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-08 09:21 UTC by Jan Pavlicek
Modified: 2018-08-17 09:54 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed/Implemented In: 5.3.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Pavlicek 2016-12-08 09:21:03 UTC
When using a class from another namespace in file that is also in a namespace, one needs to prepend the full class name with a backslash to indicate absolute path. But KDevelop fails to recognize the class with the backslash. When I remove the backslash, class is recognized (is colored and can be jumped to), but the code no longer works, because the class does not exist (it's path is resolved relative to current namespace). Demonstration:

file1.php
<?php 
namespace Test;
class A
{

}
?>

file2.php - working PHP code, but new \Test\A; is not recognized
<?php
namespace Test2;
class B
{
  public $class_a;

  public function __construct()
  {
    $this->class_a = new \Test\A;
  }
}
?>

file3.php - non working PHP code (class gets resolved to Test2\Test\A, which does not exist), but new \Test\A; is recognized as Test\A by KDevelop
<?php
namespace Test2;
class B
{
  public $class_a;

  public function __construct()
  {
    $this->class_a = new Test\A;
  }
}
?>
Comment 1 Heinz Wiesinger 2018-08-17 09:54:34 UTC
Git commit 488b24571de92a7ed7c9c55365384c8c9295bab5 by Heinz Wiesinger.
Committed on 17/08/2018 at 09:53.
Pushed by wiesinger into branch '5.3'.

Improve resolution of namespaced identifiers.

Summary:
The PST has problems matching qualified identifiers explicitely
set to global with declarations. To work around this we normalize
the namespaced identifier to be always absolute.

This means that namespace resolution inside findDeclarationImportHelper
should be correct now, but may need several calls to find the declaration
we're looking for according to the correct rules. Unfortunately, the rules
are different for classes, use declarations, functions, constants, etc.
That's why it really needs to be call-side decision on what fallbacks can
or can't be used.
FIXED-IN: 5.3.0

Reviewers: brauch

Reviewed By: brauch

Subscribers: brauch, kdevelop-devel

Tags: #kdevelop

Differential Revision: https://phabricator.kde.org/D14839

M  +7    -1    duchain/builders/contextbuilder.cpp
M  +1    -1    duchain/builders/contextbuilder.h
M  +18   -2    duchain/builders/declarationbuilder.cpp
M  +5    -2    duchain/builders/typebuilder.cpp
M  +25   -1    duchain/builders/usebuilder.cpp
M  +9    -1    duchain/expressionvisitor.cpp
M  +15   -18   duchain/helper.cpp
M  +5    -0    duchain/helper.h
M  +37   -0    duchain/tests/duchain_multiplefiles.cpp
M  +1    -0    duchain/tests/duchain_multiplefiles.h

https://commits.kde.org/kdev-php/488b24571de92a7ed7c9c55365384c8c9295bab5