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

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

[elpa] externals/phpinspect 9882ed2c60 061/126: Test/fix type inference


From: ELPA Syncer
Subject: [elpa] externals/phpinspect 9882ed2c60 061/126: Test/fix type inference of objects in nested arrays
Date: Sat, 12 Aug 2023 00:58:44 -0400 (EDT)

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

    Test/fix type inference of objects in nested arrays
---
 phpinspect.el           |  7 +++----
 test/phpinspect-test.el | 28 +++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/phpinspect.el b/phpinspect.el
index f81d6683d3..d758ea6ac8 100644
--- a/phpinspect.el
+++ b/phpinspect.el
@@ -699,10 +699,9 @@ EXPRESSION."
          (funcall
           type-resolver (phpinspect--make-type :name (cadadr expression))))
         ((and (> (length expression) 1)
-              (or (seq-find #'phpinspect-attrib-p expression)
-                  (and (= 2 (length expression))
-                       (phpinspect-variable-p (car expression))
-                       (phpinspect-array-p (car (last expression))))))
+              (seq-find (lambda (part) (or (phpinspect-attrib-p part)
+                                               (phpinspect-array-p part)))
+                        expression))
          (phpinspect--log "Variable was assigned with a derived statement")
          (phpinspect-get-derived-statement-type-in-block
           resolvecontext expression php-block
diff --git a/test/phpinspect-test.el b/test/phpinspect-test.el
index d8a120fdb3..754f6a8e5c 100644
--- a/test/phpinspect-test.el
+++ b/test/phpinspect-test.el
@@ -105,7 +105,7 @@
                                  result)))))
 
 (ert-deftest phpinspect-get-variable-type-in-block-array-access ()
-  (let* ((tokens (phpinspect-parse-string "class Foo { function a(\\Thing 
$baz) { $foo = []; $foo[] = $baz; $bar = $foo[0]; $bork = [$foo[0]]; $bark = 
$bork[0];"))
+  (let* ((tokens (phpinspect-parse-string "class Foo { function a(\\Thing 
$baz) { $foo = []; $foo[] = $baz; $bar = $foo[0]; $bork = [$foo[0]]; $bark = 
$bork[0]; $borknest = [$bork]; $barknest = $borknest[0][0]"))
          (context (phpinspect--get-resolvecontext tokens))
          (project-root "could never be a real project root")
          (phpinspect-project-root-function
@@ -159,6 +159,32 @@
       (should (phpinspect--type= (phpinspect--make-type :name "\\Thing")
                                  result)))))
 
+
+(ert-deftest phpinspect-get-variable-type-in-block-nested-array ()
+  (let* ((tokens (phpinspect-parse-string "class Foo { function a(\\Thing 
$baz) { $foo = [[$baz]]; foreach ($foo[0] as $bar) {$bar->"))
+         (context (phpinspect--get-resolvecontext tokens))
+         (project-root "could never be a real project root")
+         (phpinspect-project-root-function
+          (lambda (&rest _ignored) project-root))
+         (project (phpinspect--make-project
+                   :fs (phpinspect-make-virtual-fs)
+                   :root project-root
+                   :worker (phpinspect-make-worker))))
+
+    (puthash project-root project (phpinspect--cache-projects 
phpinspect-cache))
+
+    (let* ((function-token (seq-find #'phpinspect-function-p
+                                     
(phpinspect--resolvecontext-enclosing-tokens context)))
+           (result (phpinspect-get-variable-type-in-block
+                    context "bar"
+                    (phpinspect-function-block function-token)
+                    (phpinspect--make-type-resolver-for-resolvecontext context)
+                    (phpinspect-function-argument-list function-token))))
+
+      (should (phpinspect--type= (phpinspect--make-type :name "\\Thing")
+                                 result)))))
+
+
 (ert-deftest phpinspect--find-assignments-in-token ()
   (let* ((tokens (cadr
                   (phpinspect-parse-string "{ $foo = ['nr 1']; $bar = $nr2; if 
(true === ($foo = $nr3)) { $foo = $nr4; $notfoo = $nr5; if ([] === ($foo = [ 
$nr6 ])){ $foo = [ $nr7 ];}}}")))



reply via email to

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