From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs Subject: bug#67523: check-declare doesn't account for shorthands Date: Wed, 29 Nov 2023 11:12:11 +0000 Message-ID: References: <87o7fcgbyx.fsf@ushin.org> 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="26557"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 67523@debbugs.gnu.org, Adam Porter , Jonas Bernoulli To: Joseph Turner Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 29 12:13:10 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 1r8IVB-0006hH-TG for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 Nov 2023 12:13:10 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8IUz-0005nx-Cm; Wed, 29 Nov 2023 06:12:57 -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 1r8IUx-0005nX-7x for bug-gnu-emacs@gnu.org; Wed, 29 Nov 2023 06:12:55 -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 1r8IUw-0001UX-Vl for bug-gnu-emacs@gnu.org; Wed, 29 Nov 2023 06:12:54 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r8IV4-0003Ku-2x for bug-gnu-emacs@gnu.org; Wed, 29 Nov 2023 06:13:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 29 Nov 2023 11:13: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.170125635912787 (code B ref 67523); Wed, 29 Nov 2023 11:13:02 +0000 Original-Received: (at 67523) by debbugs.gnu.org; 29 Nov 2023 11:12:39 +0000 Original-Received: from localhost ([127.0.0.1]:49017 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r8IUh-0003KA-DL for submit@debbugs.gnu.org; Wed, 29 Nov 2023 06:12:39 -0500 Original-Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]:42485) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r8IUe-0003Jw-PL for 67523@debbugs.gnu.org; Wed, 29 Nov 2023 06:12:38 -0500 Original-Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-50bb92811c0so777120e87.1 for <67523@debbugs.gnu.org>; Wed, 29 Nov 2023 03:12:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701256343; x=1701861143; darn=debbugs.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RPfzgL4OGrX6Y/Ig6PGdu2MhQrxSPrW3igRlicJ1fL8=; b=gZaDQn5OvBHwv8WPULomghcGqG56JUh8rF1RWmWC7poKByepNoXI1z9cdYC3KWyn+b TqidgDN1/uJc+5u8tTaDKQxZRMM6PmxZM6hQfk0l1DRODEv3hBz7vsF4XerZmMQPCAv6 Ode7b3JDuR8e5j+GYIC/uUuOznfkwG9zNdy7RRwbXnc8z9309gqvBtDLGc/iNRrUiO3d fEupEUEUi1421Ot5EmS/ky88KpJbUv1uJ/ViFM6XsxIMZO5FtGXyYUc5aT6whqvMxbnk Qg6/q6FPgMWt2dRYGcLophvk53nrYdflzRyGDP4IaoOQT92JNZT8LYVMLumDn1s1uuSi k2Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701256343; x=1701861143; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RPfzgL4OGrX6Y/Ig6PGdu2MhQrxSPrW3igRlicJ1fL8=; b=w4EDoEyo7rBuq8BSHnNiZrRnhsVAsE82u4vhG36dkhh+AA6D1HXg3fjPI0aaZcBX1v 3Hkbp2GFRCPox/4WA1xQFvvAThDNMQppOO/drEfoFDho9n3iDs34WC+hvnVTWjy7Kj9Q ZklqLxKeTvOZwPKNqqpkJ1vNCbZZ/nM/x1YEiBR9Vtq+m1ZFp7MBScfGZu+0MS13JBf0 7xy/e4s1i+q5Y8864A/7kzJWJoKB+Ad2qUNBO+qhMLZxiwViZBTI8ZdPWf/qDmPfkFwW cZHzAnjhrbSpQaucsyFYHVdQLyzsBlkr/WEPeNXdQ6TGyP4THSBiPAjfMW8rJ+N1E57T dDsA== X-Gm-Message-State: AOJu0YxjNy1pzFEJa0h3LZXlsf8JE6FhRNPLjd3hfF8bMHGO57jrWrXO 4cJJe1skeV4UO1SaMuvQ86fPkqXy5CgNlRsMDqg= X-Google-Smtp-Source: AGHT+IEIGBn2wJ4Za0dft4Uf8vXL9QpiDJoBcnfFOYdeF6yJel2qDqyxeW4/NjcoI7i/NvdYMjPpaRWE07IqjkqricA= X-Received: by 2002:a05:6512:108d:b0:50b:c8c3:4580 with SMTP id j13-20020a056512108d00b0050bc8c34580mr95418lfg.10.1701256342915; Wed, 29 Nov 2023 03:12:22 -0800 (PST) In-Reply-To: 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:275215 Archived-At: 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 th= e > > > same longhand form. It might be more feasible to run re-search-forwa= rd > > > 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 na= me. > > > > 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-decla= re.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