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

    Fix bug in indexation of live edited buffer (function with preceding 
bareword in scope)
    
    Bug caused an error when inserting "private Foo" before an unscoped class
    method.
---
 phpinspect-index.el |  5 +++--
 test/test-buffer.el | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/phpinspect-index.el b/phpinspect-index.el
index f85ed7f60e..e7af78c339 100644
--- a/phpinspect-index.el
+++ b/phpinspect-index.el
@@ -89,7 +89,8 @@ of TYPE, if available."
                       type-resolver current add-used-types comment-before))
 
                (when (setq return-type (seq-find #'phpinspect-word-p 
declaration))
-                 (funcall add-used-types (list (cadr return-type)))
+                 (when add-used-types
+                   (funcall add-used-types (list (cadr return-type))))
                  (setq return-type (funcall type-resolver
                                             (phpinspect--make-type :name (cadr 
return-type)))))
 
@@ -137,7 +138,7 @@ If ADD-USED-TYPES is set, it must be a function and will be
 called with a list of the types that are used within the
 function (think \"new\" statements, return types etc.)."
   (phpinspect--log "Indexing function")
-  (let* ((php-func (cadr scope))
+  (let* ((php-func (seq-find #'phpinspect-function-p scope))
          (declaration (cadr php-func))
          name type arguments throws used-types)
 
diff --git a/test/test-buffer.el b/test/test-buffer.el
index 8f8c45a2f5..3a06e06cc5 100644
--- a/test/test-buffer.el
+++ b/test/test-buffer.el
@@ -656,3 +656,38 @@ class AccountStatisticsController {
             (should (phpinspect--type=
                      relation-type
                      (phpinspect--type-contains (phpinspect--variable-type 
relations))))))))))
+
+
+(ert-deftest phpinspect-buffer-parse-incrementally-unfinished-variable-scope ()
+  (with-temp-buffer
+  (let* ((buffer (phpinspect-make-buffer
+                  :buffer (current-buffer)
+                  :-project (phpinspect--make-dummy-project))))
+
+
+    (setq-local phpinspect-current-buffer buffer)
+    (insert
+     "<?php
+
+namespace XXX;
+
+class AAA {
+
+    function bbb () {
+        $banana = 'aaa';
+    }
+}
+
+")
+
+    (add-hook 'after-change-functions #'phpinspect-after-change-function)
+    (phpinspect-buffer-parse buffer 'no-interrupt)
+
+    ;; move to after class brace
+    (goto-char 35)
+    (insert "\n public Foo ")
+    (phpinspect-buffer-parse buffer 'no-interrupt)
+    (phpinspect-buffer-update-project-index buffer)
+
+    ;; We're just confirming that the above code doesn't error
+    (should t))))

Reply via email to