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

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

[elpa] externals/phpinspect 5c61d4b293 2/2: Implement resolving types fr


From: ELPA Syncer
Subject: [elpa] externals/phpinspect 5c61d4b293 2/2: Implement resolving types from typecasted statements
Date: Sun, 18 Aug 2024 18:58:35 -0400 (EDT)

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

    Implement resolving types from typecasted statements
---
 phpinspect-resolve.el | 12 ++++++++++--
 test/test-resolve.el  | 24 ++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/phpinspect-resolve.el b/phpinspect-resolve.el
index 785a8bb77a..a2263b6afe 100644
--- a/phpinspect-resolve.el
+++ b/phpinspect-resolve.el
@@ -503,6 +503,14 @@ value/type."
               (string= (cadar expression) "new"))
          (funcall
           type-resolver (phpinspect--make-type :name (cadadr expression))))
+
+        ((and (phpinspect-list-p (car expression))
+              (= 1 (length (cdar expression)))
+              (phpinspect-word-p (cadar expression)))
+         ;; expression starts with "(word)", so it is a type cast. Return the
+         ;; type of the cast.
+         (funcall type-resolver (phpinspect--make-type :name (car (cdadar 
expression)))))
+
         ((and (> (length expression) 1)
               (seq-find (lambda (part) (or (phpinspect-attrib-p part)
                                            (phpinspect-array-p part)))
@@ -514,8 +522,8 @@ value/type."
 
         ((phpinspect-list-p (car expression))
          (phpinspect--interpret-expression-type-in-context
-          resolvecontext php-block type-resolver (cdar expression) 
function-arg-list assignments))
-
+          resolvecontext php-block type-resolver (cdar expression)
+          function-arg-list assignments))
         ;; Expression is a (chain of) assignments. The right-most subexpression
         ;; is the type it evaluates to.
         ((seq-find #'phpinspect-assignment-p expression)
diff --git a/test/test-resolve.el b/test/test-resolve.el
index 7acdd452a5..4db7892fd6 100644
--- a/test/test-resolve.el
+++ b/test/test-resolve.el
@@ -143,3 +143,27 @@
         (should result)
         (should (phpinspect--type= (phpinspect--make-type :name "\\string")
                                    result))))))
+
+
+(ert-deftest phpinspect-get-variable-type-in-block-typecast ()
+  (let ((base-code "$foo = new \\DateTime();")
+        (paths (list "$foo = (string) $foo; $foo"
+                     "((Foo) $foo)->bar"
+                     "$baz = (string) $foo; $baz"
+                     "if ($baz = (string) $banana->bar) { $baz"))
+        (project (phpinspect--make-dummy-project)))
+
+    (phpinspect-project-add-index
+     project
+     (phpinspect--index-tokens
+      (phpinspect-parse-string "class Foo { public string $bar; }")))
+
+    (dolist (path paths)
+      (let* ((code (concat base-code path))
+             (bmap (phpinspect-parse-string-to-bmap code))
+             (context (phpinspect-get-resolvecontext project bmap (length 
code)))
+             (result (phpinspect-resolve-type-from-context context)))
+
+        (should result)
+        (should (phpinspect--type= (phpinspect--make-type :name "\\string")
+                                   result))))))



reply via email to

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