branch: externals/phpinspect
commit 62bfc7830a34e3320bbb0a8ae6a1829498abbc9f
Author: Hugo Thunnissen <de...@hugot.nl>
Commit: Hugo Thunnissen <de...@hugot.nl>

    Fix namespace resolution bug in phpinspect-fix-imports
    
    Incorrect use of phpinspect-namespace-name caused phpinspect-fix-imports to
    incorrectly determine the current namespace. This resulted in imports being
    suggested/added for types that already were available in the current
    namespace. It did not make the PHP code invalid, but it did cause 
unnecessary
    use statements for types in the same namespace.
    
    This bug has now been fixed.
---
 phpinspect-imports.el | 8 ++++++--
 phpinspect-type.el    | 5 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/phpinspect-imports.el b/phpinspect-imports.el
index 31efa763f2..fbb0cf44a7 100644
--- a/phpinspect-imports.el
+++ b/phpinspect-imports.el
@@ -31,6 +31,7 @@
 (require 'phpinspect-buffer)
 (require 'phpinspect-cache)
 (require 'phpinspect-util)
+(require 'phpinspect-type)
 
 (defun phpinspect-insert-at-point (point data)
   (save-excursion
@@ -115,12 +116,15 @@ buffer position to insert the use statement at."
     (dolist (type types)
       (setq namespace (phpinspect-meta-find-parent-matching-token
                        parent-token #'phpinspect-namespace-p)
-            namespace-name (phpinspect-namespace-name namespace))
+            namespace-name (if namespace
+                               (phpinspect-namespace-name 
(phpinspect-meta-token namespace))
+                             ""))
       ;; Add use statements for types that aren't imported or already 
referenced
       ;; with a fully qualified name.
       (unless (or (or (alist-get type imports))
                   (gethash (phpinspect-intern-name
-                            (concat namespace-name "\\" 
(phpinspect-name-string type)))
+                            (phpinspect--resolve-type-name
+                             nil namespace-name (phpinspect-name-string type)))
                            (phpinspect-autoloader-types
                             (phpinspect-project-autoload project))))
         (phpinspect-add-use-interactive type buffer project namespace)
diff --git a/phpinspect-type.el b/phpinspect-type.el
index a7c07c08f4..1ffee8a16f 100644
--- a/phpinspect-type.el
+++ b/phpinspect-type.el
@@ -358,8 +358,9 @@ mutability of the variable")
   "Extract NAMESPACE name as a string.
 
 NAMESPACE should be a namespace token (`phpinspect-namespace-p')."
-  (or (and (phpinspect-namespace-p namespace)
-           (phpinspect-word-p (cadr namespace))
+  (cl-assert (phpinspect-namespace-p namespace))
+
+  (or (and (phpinspect-word-p (cadr namespace))
            (cadadr namespace))
       ""))
 

Reply via email to