emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phpinspect d3eec5c0bd 3/4: Temporary fix for error upon


From: ELPA Syncer
Subject: [elpa] externals/phpinspect d3eec5c0bd 3/4: Temporary fix for error upon indexation of anonymous functions
Date: Thu, 31 Aug 2023 09:58:39 -0400 (EDT)

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

    Temporary fix for error upon indexation of anonymous functions
---
 phpinspect-index.el | 41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)

diff --git a/phpinspect-index.el b/phpinspect-index.el
index b89c7e4883..f545472f44 100644
--- a/phpinspect-index.el
+++ b/phpinspect-index.el
@@ -60,6 +60,27 @@ of TYPE, if available."
   (or (not type)
       (phpinspect--type= type phpinspect--object-type)))
 
+(defun phpinspect--index-function-declaration (declaration type-resolver 
add-used-types)
+  (let (current name function-args return-type)
+    (catch 'break
+      (while (setq current (pop declaration))
+        (cond ((and (phpinspect-word-p current)
+                    (phpinspect-word-p (car declaration))
+                    (string= "function" (cadr current)))
+               (setq name (cadr (pop declaration))))
+              ((phpinspect-list-p current)
+               (setq function-args
+                     (phpinspect--index-function-arg-list
+                      type-resolver current add-used-types))
+
+               (when (setq return-type (seq-find #'phpinspect-word-p 
declaration))
+                 (setq return-type (funcall type-resolver
+                                            (phpinspect--make-type :name (cadr 
return-type)))))
+
+               (throw 'break nil)))))
+
+    (list name function-args return-type)))
+
 (defun phpinspect--index-function-from-scope (type-resolver scope 
comment-before &optional add-used-types namespace)
   "Index a function inside SCOPE token using phpdoc metadata in COMMENT-BEFORE.
 
@@ -69,9 +90,16 @@ function (think \"new\" statements, return types etc.)."
   (phpinspect--log "Indexing function")
   (let* ((php-func (cadr scope))
          (declaration (cadr php-func))
-         (type (if (phpinspect-word-p (car (last declaration)))
-                   (funcall type-resolver
-                            (phpinspect--make-type :name (cadar (last 
declaration)))))))
+         name type arguments)
+
+    (pcase-setq `(,name ,arguments ,type)
+                (phpinspect--index-function-declaration
+                 declaration type-resolver add-used-types))
+
+    ;; FIXME: Anonymous functions should not be indexed! (or if they are, they
+    ;; should at least not be visible from various UIs unless assigned to a
+    ;; variable as a closure).
+    (unless name (setq name "anonymous"))
 
     (phpinspect--log "Checking function return annotations")
 
@@ -114,12 +142,9 @@ function (think \"new\" statements, return types etc.)."
     (phpinspect--make-function
      :scope `(,(car scope))
      :token php-func
-     :name (concat (if namespace (concat namespace "\\") "") (cadadr (cdr 
declaration)))
+     :name (concat (if namespace (concat namespace "\\") "") name)
      :return-type (or type phpinspect--null-type)
-     :arguments (phpinspect--index-function-arg-list
-                 type-resolver
-                 (phpinspect-function-argument-list php-func)
-                 add-used-types))))
+     :arguments arguments)))
 
 (define-inline phpinspect--safe-cadr (list)
   (inline-letevals (list)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]