all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#61691: (wrong-type-argument stringp nil) error when indenting some C code in c-ts-mode
       [not found] <m1ttzey552.fsf.ref@yahoo.es>
@ 2023-02-21 23:23 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-02-26  8:19   ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-02-21 23:23 UTC (permalink / raw)
  To: 61691

[-- Attachment #1: Type: text/plain, Size: 409 bytes --]

Tags: patch


Given the following code in c-ts-mode:

int
foo ()
{
  int c;
  if (!CHAR_VALID_P (c))
    /* This is a comment.  */
    c = 'a';

  return c;
}

If point is in line "c = 'a'" and you press TAB, a (wrong-type-argument
stringp nil) error is thrown.

The attached patch fixes the problem by checking the return value of
(treesit-node-field-name node) before passing the result to
string-match-p.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-wrong-argument-error-indenting-C-code-in-c-ts-mo.patch --]
[-- Type: text/patch, Size: 2362 bytes --]

From 6c53e473b06ade90ceb20d52dcc0d8d989601308 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= <mardani29@yahoo.es>
Date: Wed, 22 Feb 2023 00:12:31 +0100
Subject: [PATCH] Fix wrong argument error indenting C code in c-ts-mode

*
lisp/progmodes/c-ts-common.el (c-ts-common--node-is): (treesit-node-type
node) can return nil for some nodes. Protect string-match-p against
it.
---
 lisp/progmodes/c-ts-common.el                    | 10 ++++++----
 .../progmodes/c-ts-mode-resources/indent.erts    | 16 ++++++++++++++++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/lisp/progmodes/c-ts-common.el b/lisp/progmodes/c-ts-common.el
index 8262e6261d4..4fa60ab71eb 100644
--- a/lisp/progmodes/c-ts-common.el
+++ b/lisp/progmodes/c-ts-common.el
@@ -299,16 +299,18 @@ c-ts-common--node-is
     (dolist (type types)
       (let ((regexp (alist-get
                      type c-ts-common-indent-type-regexp-alist))
-            (parent (treesit-node-parent node)))
+            (parent (treesit-node-parent node))
+            (node-field-name (treesit-node-field-name node))
+            (node-type (treesit-node-type node)))
         (when (and regexp
                    (if (consp regexp)
                        (and parent
                             (string-match-p (car regexp)
                                             (treesit-node-type parent))
+                            node-field-name
                             (string-match-p (cdr regexp)
-                                            (treesit-node-field-name
-                                             node)))
-                     (string-match-p regexp (treesit-node-type node))))
+                                            node-field-name))
+                     (string-match-p regexp node-type)))
           (throw 'ret t))))
     nil))
 
diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
index 36d7af4faf1..ec4173dd214 100644
--- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
@@ -385,3 +385,19 @@ namespace test {
   };
 }
 =-=-=
+
+Name: Single Line If With Comment (GNU Style)
+
+=-=
+
+int
+foo ()
+{
+  int c;
+  if (!CHAR_VALID_P (c))
+    /* This is a comment.  */
+    c = 'a';
+
+  return c;
+}
+=-=-=
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#61691: (wrong-type-argument stringp nil) error when indenting some C code in c-ts-mode
  2023-02-21 23:23 ` bug#61691: (wrong-type-argument stringp nil) error when indenting some C code in c-ts-mode Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-02-26  8:19   ` Eli Zaretskii
  2023-02-26 11:10     ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2023-02-26  8:19 UTC (permalink / raw)
  To: Daniel Martín; +Cc: 61691

> Date: Wed, 22 Feb 2023 00:23:37 +0100
> From:  Daniel Martín via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> Given the following code in c-ts-mode:
> 
> int
> foo ()
> {
>   int c;
>   if (!CHAR_VALID_P (c))
>     /* This is a comment.  */
>     c = 'a';
> 
>   return c;
> }
> 
> If point is in line "c = 'a'" and you press TAB, a (wrong-type-argument
> stringp nil) error is thrown.

With today's emacs-29 branch, I cannot reproduce this.  Was the
problem solved meanwhile?





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#61691: (wrong-type-argument stringp nil) error when indenting some C code in c-ts-mode
  2023-02-26  8:19   ` Eli Zaretskii
@ 2023-02-26 11:10     ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-02-26 11:10 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 61691-done

Version: 29.1

Eli Zaretskii <eliz@gnu.org> writes:

>> Date: Wed, 22 Feb 2023 00:23:37 +0100
>> From:  Daniel Martín via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>> 
>> Given the following code in c-ts-mode:
>> 
>> int
>> foo ()
>> {
>>   int c;
>>   if (!CHAR_VALID_P (c))
>>     /* This is a comment.  */
>>     c = 'a';
>> 
>>   return c;
>> }
>> 
>> If point is in line "c = 'a'" and you press TAB, a (wrong-type-argument
>> stringp nil) error is thrown.
>
> With today's emacs-29 branch, I cannot reproduce this.  Was the
> problem solved meanwhile?

I cannot reproduce the issue anymore in Emacs 29, so I'm closing the bug
report.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-26 11:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <m1ttzey552.fsf.ref@yahoo.es>
2023-02-21 23:23 ` bug#61691: (wrong-type-argument stringp nil) error when indenting some C code in c-ts-mode Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-26  8:19   ` Eli Zaretskii
2023-02-26 11:10     ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.