[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 ];}}}")))
- [elpa] externals/phpinspect f8689ac9df 018/126: Return parser function in stead of just the symbol, (continued)
- [elpa] externals/phpinspect f8689ac9df 018/126: Return parser function in stead of just the symbol, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 825a3de2c4 017/126: Add indexation command to mode docstring + add install to readme, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 1e4e865c9b 021/126: Add variables nested in (function or other) blocks to candidates, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 2b85271b2b 030/126: Test + fix get-last-statement-in-token for static attribute references, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect a60dba5f11 031/126: WIP: new struct to represent types, and string comparison optimization with obarray, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 8caf967b57 029/126: Add test for resolve-type-from-context with preceding bareword, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 341afd42da 037/126: WIP: Index types in the background using collaborative threading., ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 98e88d45ac 034/126: WIP: Fix find-class-file, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 350850c07a 052/126: Fix phpinspect-index-static-methods test, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 224bbd7916 057/126: Implement array member type inference, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 9882ed2c60 061/126: Test/fix type inference of objects in nested arrays,
ELPA Syncer <=
- [elpa] externals/phpinspect 47335f3450 064/126: Refactor phpinspect--project to phpinspect-project, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 1b1cf45638 054/126: Fix bug in extended classes' method merging + add some tests, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 153ff71fcf 048/126: WIP: Implement psr0 and psr4 autoload strategies, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect e65b268cea 053/126: Implement @method annotation indexation, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect ae3acbdbe1 056/126: Disable auto-reindexing by default, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect e7b1f22e8c 068/126: Sort tokens by size when returning tokens around point, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 0e00d7e5a6 066/126: Wakeup worker when stop is requested and worker thread is paused, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect bb04e9a0f8 079/126: Implement strategy pattern for phpinspect-eldoc-function, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect f9f3440850 065/126: Make file contents insertion asynchronous in background threads, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect ad5ede01ad 071/126: Implement Incremental Parsing, ELPA Syncer, 2023/08/12