diff options
| author | Mattias EngdegÄrd | 2023-09-17 12:49:40 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2023-09-17 17:16:35 +0200 |
| commit | f8ea47ebf45c5ea0cd788667f7bdb805f42e08e0 (patch) | |
| tree | e494cdd6d08b6a38de3ce5d346feb2eb3f501e1c /test | |
| parent | e0070fc574a8621b2fbb1aaca678b974a3dc5fd5 (diff) | |
| download | emacs-f8ea47ebf45c5ea0cd788667f7bdb805f42e08e0.tar.gz emacs-f8ea47ebf45c5ea0cd788667f7bdb805f42e08e0.zip | |
Expanded defcustom type byte-compilation warnings (bug#65852)
Warn about more kinds of mistakes in :type arguments of `defcustom`
and `define-widget`. These include:
- misplaced keyword args, as in (const red :tag "A reddish hue")
- missing subordinate types, as in (repeat :tag "List of names")
or (choice list string)
- duplicated values, as in (choice (const yes) (const yes))
- misplaced `other` member, as in
(choice (const red) (other nil) (const blue))
- various type name mistakes, as in (vector bool functionp)
* lisp/emacs-lisp/bytecomp.el (byte-compile--defcustom-type-quoted)
(byte-compile-nogroup-warn): Remove.
(byte-compile-normal-call): Remove call to the above.
(bytecomp--cus-warn, bytecomp--check-cus-type)
(bytecomp--custom-declare): New.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/bytecomp-tests.el | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index 03aed5263b6..a335a7fa1f8 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el | |||
| @@ -1100,7 +1100,7 @@ byte-compiled. Run with dynamic binding." | |||
| 1100 | "fails to specify containing group") | 1100 | "fails to specify containing group") |
| 1101 | 1101 | ||
| 1102 | (bytecomp--define-warning-file-test "warn-defcustom-notype.el" | 1102 | (bytecomp--define-warning-file-test "warn-defcustom-notype.el" |
| 1103 | "fails to specify type") | 1103 | "missing :type keyword parameter") |
| 1104 | 1104 | ||
| 1105 | (bytecomp--define-warning-file-test "warn-defvar-lacks-prefix.el" | 1105 | (bytecomp--define-warning-file-test "warn-defvar-lacks-prefix.el" |
| 1106 | "var.*foo.*lacks a prefix") | 1106 | "var.*foo.*lacks a prefix") |
| @@ -1874,12 +1874,50 @@ EXPECTED-POINT BINDINGS (MODES \\='\\='(ruby-mode js-mode python-mode)) \ | |||
| 1874 | (TEST-IN-COMMENTS t) (TEST-IN-STRINGS t) (TEST-IN-CODE t) \ | 1874 | (TEST-IN-COMMENTS t) (TEST-IN-STRINGS t) (TEST-IN-CODE t) \ |
| 1875 | (FIXTURE-FN \\='#\\='electric-pair-mode))" fill-column))) | 1875 | (FIXTURE-FN \\='#\\='electric-pair-mode))" fill-column))) |
| 1876 | 1876 | ||
| 1877 | (ert-deftest bytecomp-test-defcustom-type-quoted () | 1877 | (ert-deftest bytecomp-test-defcustom-type () |
| 1878 | (should-not (byte-compile--defcustom-type-quoted 'integer)) | 1878 | (cl-flet ((dc (type) `(defcustom mytest nil "doc" :type ',type))) |
| 1879 | (should-not (byte-compile--defcustom-type-quoted | 1879 | (bytecomp--with-warning-test |
| 1880 | '(choice (const :tag "foo" bar)))) | 1880 | (rx "type should not be quoted") (dc ''integer)) |
| 1881 | (should (byte-compile--defcustom-type-quoted | 1881 | (bytecomp--with-warning-test |
| 1882 | '(choice (const :tag "foo" 'bar))))) | 1882 | (rx "type should not be quoted") (dc '(choice '(repeat boolean)))) |
| 1883 | (bytecomp--with-warning-test | ||
| 1884 | (rx "misplaced :tag keyword") (dc '(choice (const b :tag "a")))) | ||
| 1885 | (bytecomp--with-warning-test | ||
| 1886 | (rx "`choice' without any types inside") (dc '(choice :tag "a"))) | ||
| 1887 | (bytecomp--with-warning-test | ||
| 1888 | (rx "`other' not last in `choice'") | ||
| 1889 | (dc '(choice (const a) (other b) (const c)))) | ||
| 1890 | (bytecomp--with-warning-test | ||
| 1891 | (rx "duplicated value in `choice': `a'") | ||
| 1892 | (dc '(choice (const a) (const b) (const a)))) | ||
| 1893 | (bytecomp--with-warning-test | ||
| 1894 | (rx "`cons' requires 2 type specs, found 1") | ||
| 1895 | (dc '(cons :tag "a" integer))) | ||
| 1896 | (bytecomp--with-warning-test | ||
| 1897 | (rx "`repeat' without type specs") | ||
| 1898 | (dc '(repeat :tag "a"))) | ||
| 1899 | (bytecomp--with-warning-test | ||
| 1900 | (rx "`const' with too many values") | ||
| 1901 | (dc '(const :tag "a" x y))) | ||
| 1902 | (bytecomp--with-warning-test | ||
| 1903 | (rx "`const' with quoted value") | ||
| 1904 | (dc '(const :tag "a" 'x))) | ||
| 1905 | (bytecomp--with-warning-test | ||
| 1906 | (rx "`bool' is not a valid type") | ||
| 1907 | (dc '(bool :tag "a"))) | ||
| 1908 | (bytecomp--with-warning-test | ||
| 1909 | (rx "irregular type `:tag'") | ||
| 1910 | (dc '(:tag "a"))) | ||
| 1911 | (bytecomp--with-warning-test | ||
| 1912 | (rx "irregular type `\"string\"'") | ||
| 1913 | (dc '(list "string"))) | ||
| 1914 | (bytecomp--with-warning-test | ||
| 1915 | (rx "`list' without arguments") | ||
| 1916 | (dc 'list)) | ||
| 1917 | (bytecomp--with-warning-test | ||
| 1918 | (rx "`integerp' is not a valid type") | ||
| 1919 | (dc 'integerp)) | ||
| 1920 | )) | ||
| 1883 | 1921 | ||
| 1884 | (ert-deftest bytecomp-function-attributes () | 1922 | (ert-deftest bytecomp-function-attributes () |
| 1885 | ;; Check that `byte-compile' keeps the declarations, interactive spec and | 1923 | ;; Check that `byte-compile' keeps the declarations, interactive spec and |