diff options
| author | Philipp Stephani | 2017-09-02 21:08:04 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2017-09-02 21:08:04 +0200 |
| commit | 71766a45f1edb02ec5107803a7f7a8e17809b093 (patch) | |
| tree | a2b5f8d72f6a6213646814fa0c6c8556617b23ea | |
| parent | dbe1e55dc4064e82813f6b84ee4297d8fc45b2fc (diff) | |
| download | emacs-71766a45f1edb02ec5107803a7f7a8e17809b093.tar.gz emacs-71766a45f1edb02ec5107803a7f7a8e17809b093.zip | |
Improve error messages for improper plists (Bug#27726)
* src/fns.c (Fplist_put, Flax_plist_get, Flax_plist_put)
(Fplist_member, syms_of_fns): Use ‘plistp’ as pseudo-predicate for
improper plists instead of ‘listp.’
* test/src/fns-tests.el (plist-get/odd-number-of-elements)
(lax-plist-get/odd-number-of-elements)
(plist-put/odd-number-of-elements)
(lax-plist-put/odd-number-of-elements)
(plist-member/improper-list): Add unit tests.
| -rw-r--r-- | src/fns.c | 9 | ||||
| -rw-r--r-- | test/src/fns-tests.el | 28 |
2 files changed, 33 insertions, 4 deletions
| @@ -2021,7 +2021,7 @@ The PLIST is modified by side effects. */) | |||
| 2021 | if (EQ (tail, li.tortoise)) | 2021 | if (EQ (tail, li.tortoise)) |
| 2022 | circular_list (plist); | 2022 | circular_list (plist); |
| 2023 | } | 2023 | } |
| 2024 | CHECK_LIST_END (tail, plist); | 2024 | CHECK_TYPE (NILP (tail), Qplistp, plist); |
| 2025 | Lisp_Object newcell | 2025 | Lisp_Object newcell |
| 2026 | = Fcons (prop, Fcons (val, NILP (prev) ? plist : XCDR (XCDR (prev)))); | 2026 | = Fcons (prop, Fcons (val, NILP (prev) ? plist : XCDR (XCDR (prev)))); |
| 2027 | if (NILP (prev)) | 2027 | if (NILP (prev)) |
| @@ -2061,7 +2061,7 @@ one of the properties on the list. */) | |||
| 2061 | circular_list (plist); | 2061 | circular_list (plist); |
| 2062 | } | 2062 | } |
| 2063 | 2063 | ||
| 2064 | CHECK_LIST_END (tail, plist); | 2064 | CHECK_TYPE (NILP (tail), Qplistp, plist); |
| 2065 | 2065 | ||
| 2066 | return Qnil; | 2066 | return Qnil; |
| 2067 | } | 2067 | } |
| @@ -2093,7 +2093,7 @@ The PLIST is modified by side effects. */) | |||
| 2093 | if (EQ (tail, li.tortoise)) | 2093 | if (EQ (tail, li.tortoise)) |
| 2094 | circular_list (plist); | 2094 | circular_list (plist); |
| 2095 | } | 2095 | } |
| 2096 | CHECK_LIST_END (tail, plist); | 2096 | CHECK_TYPE (NILP (tail), Qplistp, plist); |
| 2097 | Lisp_Object newcell = list2 (prop, val); | 2097 | Lisp_Object newcell = list2 (prop, val); |
| 2098 | if (NILP (prev)) | 2098 | if (NILP (prev)) |
| 2099 | return newcell; | 2099 | return newcell; |
| @@ -2858,7 +2858,7 @@ The value is actually the tail of PLIST whose car is PROP. */) | |||
| 2858 | if (EQ (tail, li.tortoise)) | 2858 | if (EQ (tail, li.tortoise)) |
| 2859 | circular_list (tail); | 2859 | circular_list (tail); |
| 2860 | } | 2860 | } |
| 2861 | CHECK_LIST_END (tail, plist); | 2861 | CHECK_TYPE (NILP (tail), Qplistp, plist); |
| 2862 | return Qnil; | 2862 | return Qnil; |
| 2863 | } | 2863 | } |
| 2864 | 2864 | ||
| @@ -5191,6 +5191,7 @@ Used by `featurep' and `require', and altered by `provide'. */); | |||
| 5191 | Fmake_var_non_special (Qfeatures); | 5191 | Fmake_var_non_special (Qfeatures); |
| 5192 | DEFSYM (Qsubfeatures, "subfeatures"); | 5192 | DEFSYM (Qsubfeatures, "subfeatures"); |
| 5193 | DEFSYM (Qfuncall, "funcall"); | 5193 | DEFSYM (Qfuncall, "funcall"); |
| 5194 | DEFSYM (Qplistp, "plistp"); | ||
| 5194 | 5195 | ||
| 5195 | #ifdef HAVE_LANGINFO_CODESET | 5196 | #ifdef HAVE_LANGINFO_CODESET |
| 5196 | DEFSYM (Qcodeset, "codeset"); | 5197 | DEFSYM (Qcodeset, "codeset"); |
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index e294859226c..73c6593caf7 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el | |||
| @@ -547,4 +547,32 @@ | |||
| 547 | (should-error (nconc (cyc1 1) 'tail) :type 'circular-list) | 547 | (should-error (nconc (cyc1 1) 'tail) :type 'circular-list) |
| 548 | (should-error (nconc (cyc2 1 2) 'tail) :type 'circular-list)) | 548 | (should-error (nconc (cyc2 1 2) 'tail) :type 'circular-list)) |
| 549 | 549 | ||
| 550 | (ert-deftest plist-get/odd-number-of-elements () | ||
| 551 | "Test that ‘plist-get’ doesn’t signal an error on degenerate plists." | ||
| 552 | (should-not (plist-get '(:foo 1 :bar) :bar))) | ||
| 553 | |||
| 554 | (ert-deftest lax-plist-get/odd-number-of-elements () | ||
| 555 | "Check for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27726." | ||
| 556 | (should (equal (should-error (lax-plist-get '(:foo 1 :bar) :bar) | ||
| 557 | :type 'wrong-type-argument) | ||
| 558 | '(wrong-type-argument plistp (:foo 1 :bar))))) | ||
| 559 | |||
| 560 | (ert-deftest plist-put/odd-number-of-elements () | ||
| 561 | "Check for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27726." | ||
| 562 | (should (equal (should-error (plist-put '(:foo 1 :bar) :zot 2) | ||
| 563 | :type 'wrong-type-argument) | ||
| 564 | '(wrong-type-argument plistp (:foo 1 :bar))))) | ||
| 565 | |||
| 566 | (ert-deftest lax-plist-put/odd-number-of-elements () | ||
| 567 | "Check for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27726." | ||
| 568 | (should (equal (should-error (lax-plist-put '(:foo 1 :bar) :zot 2) | ||
| 569 | :type 'wrong-type-argument) | ||
| 570 | '(wrong-type-argument plistp (:foo 1 :bar))))) | ||
| 571 | |||
| 572 | (ert-deftest plist-member/improper-list () | ||
| 573 | "Check for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27726." | ||
| 574 | (should (equal (should-error (plist-member '(:foo 1 . :bar) :qux) | ||
| 575 | :type 'wrong-type-argument) | ||
| 576 | '(wrong-type-argument plistp (:foo 1 . :bar))))) | ||
| 577 | |||
| 550 | (provide 'fns-tests) | 578 | (provide 'fns-tests) |