From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#67523: check-declare doesn't account for shorthands Date: Sun, 10 Dec 2023 02:57:50 -0800 Message-ID: <87plzenx30.fsf@ushin.org> References: <87o7fcgbyx.fsf@ushin.org> Reply-To: Joseph Turner Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10316"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 67523@debbugs.gnu.org, Adam Porter , Jonas Bernoulli To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 10 11:59:09 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rCHWe-0002TW-6q for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Dec 2023 11:59:08 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rCHWM-0000PM-Us; Sun, 10 Dec 2023 05:58:50 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rCHWK-0000P5-A9 for bug-gnu-emacs@gnu.org; Sun, 10 Dec 2023 05:58:48 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rCHWK-0004jx-1d for bug-gnu-emacs@gnu.org; Sun, 10 Dec 2023 05:58:48 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rCHWY-0007RT-4L for bug-gnu-emacs@gnu.org; Sun, 10 Dec 2023 05:59:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Joseph Turner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 10 Dec 2023 10:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67523 X-GNU-PR-Package: emacs Original-Received: via spool by 67523-submit@debbugs.gnu.org id=B67523.170220591228562 (code B ref 67523); Sun, 10 Dec 2023 10:59:02 +0000 Original-Received: (at 67523) by debbugs.gnu.org; 10 Dec 2023 10:58:32 +0000 Original-Received: from localhost ([127.0.0.1]:49578 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rCHW4-0007Qb-1C for submit@debbugs.gnu.org; Sun, 10 Dec 2023 05:58:32 -0500 Original-Received: from out-183.mta1.migadu.com ([95.215.58.183]:49357) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rCHW1-0007QR-A6 for 67523@debbugs.gnu.org; Sun, 10 Dec 2023 05:58:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ushin.org; s=key1; t=1702205894; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c0PAf4hgll/dYGs49fGAIW+1akBw9q5kRT4EzmKn2z8=; b=WnLJYfEsFP3XgzQi3K1IvXBQ8xP+3z1yB/6zbfUTh/d9neqznzNExPCittZbU4C84OovvB u4UVHnmLJ8Kb4922eKvsGrHqt8kZrl+/wr95DcdNQ28iMlS76NBXTaVYnNKv1068IG8NyR o5ng+AF8Zu6yasP9dwiG/yZgcY0XzHqcKBNiOYXlnyaFvDdeDkBa+pnNGCRW1taRyIEjQn Y/6TCL4peGE0T6Ag/Gb3x1HQK42LmRyJh2SUZM8ITKCEuqVcFZ5lFY5SpagheNacs7SxW7 XU1zQQTJKnb39we1vOS26IVyfP5FFJzn9KMzGVkWvpTPq9+wEU6I+VoLtz3eqg== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: X-Migadu-Flow: FLOW_OUT X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:275912 Archived-At: Jo=C3=A3o T=C3=A1vora writes: > On Wed, Nov 29, 2023 at 10:35=E2=80=AFAM Jo=C3=A3o T=C3=A1vora wrote: >> >> On Wed, Nov 29, 2023 at 9:56=E2=80=AFAM Jo=C3=A3o T=C3=A1vora wrote: >> > >> > On Wed, Nov 29, 2023 at 9:12=E2=80=AFAM Joseph Turner wrote: >> > >> > > A potential solution could be to convert the longhand symbol into its >> > > shorthand form and pass that into re-search-forward. This is tricky >> > > since there may be multiple different shorthands which could yield t= he >> > > same longhand form. It might be more feasible to run re-search-forw= ard >> > > on a known common suffix portion of the symbol name, then with point= on >> > > the suspected definition, run `intern-soft' to get the full symbol n= ame. >> > >> > No, this is brittle. Check-declare, if it's to be useful (is it?) >> > is probably meant to be as precise as possible. >> > >> > > A workaround is to not use shorthands in function definitions. >> > >> > That's letting the bad guys win :-) >> > >> > > Thoughts? >> > >> > As usual, my thoughts are that tools that read Lisp code >> > should use the Lisp reader, not regular expressions. >> > >> > Here, check-declare should just walk the whole file. >> >> Or maybe just this 100% guaranteed untested patch would work: > > Sorry, that was 100% untested indeed. This patch seems to work: > > diff --git a/lisp/emacs-lisp/check-declare.el b/lisp/emacs-lisp/check-dec= lare.el > index c887d95210c..bc3844ca9be 100644 > --- a/lisp/emacs-lisp/check-declare.el > +++ b/lisp/emacs-lisp/check-declare.el > @@ -145,21 +145,26 @@ check-declare-verify > (if (file-regular-p fnfile) > (with-temp-buffer > (insert-file-contents fnfile) > + (unless cflag > + ;; for syntax and shorthands > + (lisp-data-mode) > + (hack-local-variables)) > ;; defsubst's don't _have_ to be known at compile time. > - (setq re (format (if cflag > - "^[ \t]*\\(DEFUN\\)[ \t]*([ \t]*\"%s\"" > - "^[ \t]*(\\(fset[ \t]+'\\|\ > + (setq re (if cflag > + (format "^[ \t]*\\(DEFUN\\)[ \t]*([ \t]*\"%s\"" > + (regexp-opt (mapcar 'cadr fnlist) t)) > + "^[ \t]*(\\(fset[ \t]+'\\|\ > cl-def\\(?:generic\\|method\\|un\\)\\|\ > def\\(?:un\\|subst\\|foo\\|method\\|class\\|\ > ine-\\(?:derived\\|generic\\|\\(?:global\\(?:ized\\)?-\\)?minor\\)-mode\= \|\ > \\(?:ine-obsolete-function-\\)?alias[ \t]+'\\|\ > ine-overloadable-function\\)\\)\ > -[ \t]*%s\\([ \t;]+\\|$\\)") > - (regexp-opt (mapcar 'cadr fnlist) t))) > +[ \t]*\\(\\(?:\\sw\\|\\s_\\)+\\)\\([ \t;]+\\|$\\)")) > (while (re-search-forward re nil t) > (skip-chars-forward " \t\n") > - (setq fn (match-string 2) > - type (match-string 1) > + (setq fn (symbol-name (car (read-from-string (match-string 2= ))))) > + (when (member fn (mapcar 'cadr fnlist)) > + (setq type (match-string 1) > ;; (min . max) for a fixed number of arguments, or > ;; arglists with optional elements. > ;; (min) for arglists with &rest. > @@ -202,7 +207,7 @@ check-declare-verify > (t > 'err)) > ;; alist of functions and arglist signatures. > - siglist (cons (cons fn sig) siglist))))) > + siglist (cons (cons fn sig) siglist)))))) > (dolist (e fnlist) > (setq arglist (nth 2 e) > type IIUC, this patch is being merged in response to bug#67390.