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

    Fix bug in indexation and index-deletion of in-buffer constants
    
    Deletion would crash, as the indexation function could wrongly use a 
non-string
    datatype as the name of the constant. This resulted in a failing typecheck 
(and
    often a frozen emacs because of the massive stacktrace)
---
 phpinspect-index.el            |  9 ++++----
 phpinspect-project.el          |  4 ++--
 phpinspect-resolve.el          |  4 ++--
 phpinspect-type.el             |  4 ++--
 test/phpinspect-test.el        |  1 +
 test/test-buffer-indexation.el | 50 ++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/phpinspect-index.el b/phpinspect-index.el
index 89ba2ca14d..ee9f1f27d2 100644
--- a/phpinspect-index.el
+++ b/phpinspect-index.el
@@ -191,10 +191,11 @@ function (think \"new\" statements, return types etc.)."
      (when (listp ,list) (cadr ,list)))))
 
 (defun phpinspect--index-const-from-scope (scope)
-  (phpinspect--make-variable
-   :scope `(,(car scope))
-   :mutability `(,(caadr scope))
-   :name (phpinspect--safe-cadr (phpinspect--safe-cadr (phpinspect--safe-cadr 
scope)))))
+  (let ((const-block (cadr scope)))
+    (phpinspect--make-variable
+     :scope `(,(car scope))
+     :mutability `(,(car const-block))
+     :name (cadr (seq-find #'phpinspect-word-p (cdr const-block))))))
 
 (defun phpinspect--var-annotations-from-token (token)
   (seq-filter #'phpinspect-var-annotation-p token))
diff --git a/phpinspect-project.el b/phpinspect-project.el
index 3e02bb1357..582b7bbbff 100644
--- a/phpinspect-project.el
+++ b/phpinspect-project.el
@@ -122,8 +122,8 @@ serious performance hits. Enable at your own risk (:")
 
       indexed)))
 
-(cl-defmethod phpinspect-project-add-index ((_project phpinspect-project) 
index)
-  (cl-assert (not index))
+(cl-defmethod phpinspect-project-add-index ((_project phpinspect-project) 
_index)
+  (cl-assert (not _index))
   (phpinspect--log "phpinspect-project-add-index: ignoring added nil index"))
 
 (cl-defmethod phpinspect-project-set-function
diff --git a/phpinspect-resolve.el b/phpinspect-resolve.el
index 48b4abf0c0..6e02abadeb 100644
--- a/phpinspect-resolve.el
+++ b/phpinspect-resolve.el
@@ -632,11 +632,11 @@ CLASS-TOKEN-META as parse result."
        nil))))
 
 (cl-defmethod phpi-typedef-resolve-property-type
-  ((_typedef phpinspect-typedef) (_project phpinspect-project) property-name 
&rest _ignored)
+  ((_typedef phpinspect-typedef) (_project phpinspect-project) _property-name 
&rest _ignored)
   ;; Catch-all for cases where one attempts to resolve a nil property
   ;; name. Saves an if-statement for the caller.
   ;; Can't resolve property type when property name is nil, so we do nothing.
-  (cl-assert (not property-name))
+  (cl-assert (not _property-name))
   nil)
 
 (provide 'phpinspect-resolve)
diff --git a/phpinspect-type.el b/phpinspect-type.el
index 05d78711db..91bfa807bb 100644
--- a/phpinspect-type.el
+++ b/phpinspect-type.el
@@ -277,8 +277,8 @@ NAMESPACE may be nil, or a string with a namespace FQN."
         (concat self "<" (phpinspect--format-type-name 
(phpinspect--type-format-display-name type)) ">")
       self)))
 
-(cl-defmethod phpinspect--display-format-type-name (type)
-  (cl-assert (not type))
+(cl-defmethod phpinspect--display-format-type-name (_type)
+  (cl-assert (not _type))
 
   (phpinspect--display-format-type-name "unknown-type"))
 
diff --git a/test/phpinspect-test.el b/test/phpinspect-test.el
index 719b0a63f0..423f552d97 100644
--- a/test/phpinspect-test.el
+++ b/test/phpinspect-test.el
@@ -322,6 +322,7 @@ class FlufferUpper
 (load-file (concat phpinspect-test-directory "/test-fs.el"))
 (load-file (concat phpinspect-test-directory "/test-project.el"))
 (load-file (concat phpinspect-test-directory "/test-buffer.el"))
+(load-file (concat phpinspect-test-directory "/test-buffer-indexation.el"))
 (load-file (concat phpinspect-test-directory "/test-index.el"))
 (load-file (concat phpinspect-test-directory "/test-typedef.el"))
 (load-file (concat phpinspect-test-directory "/test-type.el"))
diff --git a/test/test-buffer-indexation.el b/test/test-buffer-indexation.el
new file mode 100644
index 0000000000..66a2090638
--- /dev/null
+++ b/test/test-buffer-indexation.el
@@ -0,0 +1,50 @@
+;;; test-buffer-indexation.el --- Tests for buffer indexation  -*- 
lexical-binding: t; -*-
+
+;; Copyright (C) 2024  Hugo Thunnissen
+
+;; Author: Hugo Thunnissen <de...@hugot.nl>
+;; Keywords:
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'phpinspect-buffer)
+(require 'phpinspect-test-env
+         (expand-file-name "phpinspect-test-env.el"
+                           (file-name-directory (macroexp-file-name))))
+
+(ert-deftest phpinspect-index-incomplete-class-const ()
+  "This is a functional test, to confirm that indexation is executed
+without errors being thrown."
+  (with-temp-buffer
+    (let ((buffer (phpinspect-claim-buffer (current-buffer) 
(phpinspect--make-dummy-project))))
+      (insert "class C { private ?\\DateTime $d; public function __construct() 
{}")
+      (phpinspect-buffer-update-project-index buffer)
+
+      (goto-char 10)
+      (insert " const ")
+
+      (message (buffer-string))
+      (phpinspect-buffer-update-project-index buffer)
+      (insert "a")
+      (phpinspect-buffer-update-project-index buffer))))
+
+
+(provide 'test-buffer-indexation)
+;;; test-buffer-indexation.el ends here

Reply via email to