[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phpinspect f030a685d2 060/126: Alter interpret-expressi
From: |
ELPA Syncer |
Subject: |
[elpa] externals/phpinspect f030a685d2 060/126: Alter interpret-expression-type to interpret array-member assignment |
Date: |
Sat, 12 Aug 2023 00:58:44 -0400 (EDT) |
branch: externals/phpinspect
commit f030a685d21cfa6481073bfdfd3f6031aa02dd21
Author: Hugo Thunnissen <devel@hugot.nl>
Commit: Hugo Thunnissen <devel@hugot.nl>
Alter interpret-expression-type to interpret array-member assignment
interpret-expression-type now interprets assignment values provided through
array access as derived statements. This makes type inference work for cases
like `[$foo[0]]`, where it did not before.
---
phpinspect.el | 18 ++++++------------
test/phpinspect-test.el | 23 ++++++++++++++++-------
2 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/phpinspect.el b/phpinspect.el
index 7423ca5bd6..f81d6683d3 100644
--- a/phpinspect.el
+++ b/phpinspect.el
@@ -659,17 +659,8 @@ resolve types of function argument variables."
resolvecontext concat-pattern php-block
type-resolver function-arg-list))))
- ;; Detect array access
- (if (and last-assignment-value result
- (< 1 (length last-assignment-value))
- (phpinspect-array-p (car (last last-assignment-value))))
- (progn
- (phpinspect--log (concat
- "Detected array access in last assignment of
pattern %s"
- ", collection type: %s")
- pattern-code result)
- (phpinspect--type-contains result))
- result)))
+ ; return
+ result))
(defun phpinspect--interpret-expression-type-in-context
@@ -708,7 +699,10 @@ EXPRESSION."
(funcall
type-resolver (phpinspect--make-type :name (cadadr expression))))
((and (> (length expression) 1)
- (seq-find #'phpinspect-attrib-p expression))
+ (or (seq-find #'phpinspect-attrib-p expression)
+ (and (= 2 (length expression))
+ (phpinspect-variable-p (car expression))
+ (phpinspect-array-p (car (last 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 75f149fac0..d8a120fdb3 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];"))
+ (let* ((tokens (phpinspect-parse-string "class Foo { function a(\\Thing
$baz) { $foo = []; $foo[] = $baz; $bar = $foo[0]; $bork = [$foo[0]]; $bark =
$bork[0];"))
(context (phpinspect--get-resolvecontext tokens))
(project-root "could never be a real project root")
(phpinspect-project-root-function
@@ -118,13 +118,22 @@
(puthash project-root project (phpinspect--cache-projects
phpinspect-cache))
(let* ((function-token (car (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))))
+ (result1 (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)))
+ (result2 (phpinspect-get-variable-type-in-block
+ context "bark"
+ (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)))))
+ result1))
+ (should (phpinspect--type= (phpinspect--make-type :name "\\Thing")
+ result2)))))
+
(ert-deftest phpinspect-get-variable-type-in-block-array-foreach ()
(let* ((tokens (phpinspect-parse-string "class Foo { function a(\\Thing
$baz) { $foo = []; $foo[] = $baz; foreach ($foo as $bar) {$bar->"))
- [elpa] externals/phpinspect fbfcf4f928 119/126: Fix byte compilation warnings, (continued)
- [elpa] externals/phpinspect fbfcf4f928 119/126: Fix byte compilation warnings, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect e4b62c0230 120/126: Implement completion-at-point function, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect df821c4039 023/126: Add ticket tracker link to README, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 9f7931a7b6 100/126: Rework parser for ahead of time byte compilation, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 9513cbc917 125/126: Update README, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect e35caa7e15 118/126: Fix a variety of bugs, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect f7d88a90f4 009/126: Implement some general tests for the parser code, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 74bd0ad434 032/126: WIP: New data type for cached classes, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 3a3e2cd362 042/126: Update README with new development repository location, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 0bc9e795b2 043/126: Fix tests and patch bugs that came to light in the process, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect f030a685d2 060/126: Alter interpret-expression-type to interpret array-member assignment,
ELPA Syncer <=
- [elpa] externals/phpinspect 8cd4dc2025 058/126: Remove commented code + tidy some formatting, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect e067a9e9dd 122/126: Remove obsolete function and add some documentation to mode doc string, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 5fe0b7bdc5 123/126: Add .cask directory to gitignore, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect 15c175dc61 016/126: Only attempt to byte compile when the handler isn't already compiled, ELPA Syncer, 2023/08/12
- [elpa] externals/phpinspect dbbc5927e4 022/126: Enable company-mode before changing its variables in README example, ELPA Syncer, 2023/08/12