From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Paul Pogonyshev Newsgroups: gmane.emacs.bugs Subject: bug#51982: Erroneous handling of local variables in byte-compiled nested lambdas Date: Fri, 19 Nov 2021 21:31:13 +0100 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="000000000000a5e8da05d12a282e" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31896"; mail-complaints-to="usenet@ciao.gmane.io" To: 51982@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 19 21:32:15 2021 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 1moAYQ-000881-6q for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 19 Nov 2021 21:32:14 +0100 Original-Received: from localhost ([::1]:43912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1moAYO-0004dk-QL for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 19 Nov 2021 15:32:12 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:51238) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1moAYF-0004dL-7t for bug-gnu-emacs@gnu.org; Fri, 19 Nov 2021 15:32:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57306) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1moAYE-00084c-TM for bug-gnu-emacs@gnu.org; Fri, 19 Nov 2021 15:32:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1moAYE-0006Tk-F0 for bug-gnu-emacs@gnu.org; Fri, 19 Nov 2021 15:32:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Paul Pogonyshev Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 19 Nov 2021 20:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 51982 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.163735389624863 (code B ref -1); Fri, 19 Nov 2021 20:32:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 19 Nov 2021 20:31:36 +0000 Original-Received: from localhost ([127.0.0.1]:40619 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1moAXn-0006Sx-Rv for submit@debbugs.gnu.org; Fri, 19 Nov 2021 15:31:36 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:45562) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1moAXl-0006Sp-Nb for submit@debbugs.gnu.org; Fri, 19 Nov 2021 15:31:33 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:51082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1moAXl-0004aI-Hw for bug-gnu-emacs@gnu.org; Fri, 19 Nov 2021 15:31:33 -0500 Original-Received: from [2a00:1450:4864:20::529] (port=33334 helo=mail-ed1-x529.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1moAXe-0007vG-RF for bug-gnu-emacs@gnu.org; Fri, 19 Nov 2021 15:31:33 -0500 Original-Received: by mail-ed1-x529.google.com with SMTP id t5so47800546edd.0 for ; Fri, 19 Nov 2021 12:31:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=g5Zs4MTGtu2gvyWPcqkEHir87kJdXKULalDFNxCLweA=; b=YJfNSuyqa9ks+v/YK5PHgdf8P+OxqSZS6B+vsOATyxbhZwP/gdUuIF1e0VATyhHwp/ QKNS4E6U+txcGOerx+QtJQ22S8LDjbzVJMwUCMwf+Ewwum8WIKsMmGcqjfOzoCI1B0Ln 2lPblh4cQjLGrFOK3M6VkZCRpGcYPEz9BDW5iPgHDFH/1eY0oBBgp8TvT11t6icIflll b5r/V3iItkhG9XAdbTlWORL/cwCMktC7iXgD7XkaPrXHFwPxOXZUiuxhi5IQI+X3/sNP +Qg8qStqhKcICODDRGVIlqsbPQThrQfcKu4iyiQ9pnh1CneXN9UQ3Z+vBktm5PMeNBLb YMSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=g5Zs4MTGtu2gvyWPcqkEHir87kJdXKULalDFNxCLweA=; b=7LFgZPuaA1rIlPCMrUWeS66JXH4iKrjhNo+oAYW2EIfczwcSY13C5CRqDl9JL8pgyL LtSmYCPy3yv1lYEvg7Z/Dj+HXXcvQ9BEoim6IR+xnxFRmzixFwOudE57CYSUMcGoJ8Mk eaEEHjHHZgwvTs1YYBt0ACXCsMIUEqvoGQJQFoIURjfGtlLCZY1rBCfWeoB4pTY4UKOR JoTdcEb/TSbpk2BBl6j/0pu5zvUSOWUQSMhtKjyRRIvd10RRVAtghUOGSkIWgjZC8lW+ 2Tv5BTxCSn04mxJMIawYHBdcU7LYtycAcc23zzldBQePVUoAYFfdSEIMh4sQJ3GOyqtS Qs4w== X-Gm-Message-State: AOAM533LfQ1qR8uMBPVqC0gbdd3sPL/ov+a4umXvr4HvmuItk4hXx1D2 YIwIpk7pRmjMdawyx0caPlYkx4FQ9Jeu6uZTU5QvzB2jAQ== X-Google-Smtp-Source: ABdhPJxZ6dOV+PlbifOWhfYdZ5pm9wgS2Kqx5p+iWCL0VaywbJ23X/e7T1or24D69vs8vMCCTesfgfpCjyGCQg0Np38= X-Received: by 2002:a17:907:3f24:: with SMTP id hq36mr11470790ejc.390.1637353884336; Fri, 19 Nov 2021 12:31:24 -0800 (PST) X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::529 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=pogonyshev@gmail.com; helo=mail-ed1-x529.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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" Xref: news.gmane.io gmane.emacs.bugs:220436 Archived-At: --000000000000a5e8da05d12a282e Content-Type: multipart/alternative; boundary="000000000000a5e8d605d12a282c" --000000000000a5e8d605d12a282c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Steps to reproduce: 1) save attached file as `wtf.el'; 2) execute from command line: $ emacs --batch --eval "(byte-compile-file \"wtf.el\")" $ emacs --batch -L . --eval "(require 'wtf)" --eval "(print (funcall (wtf 1)))" Results, of the first command (byte-compilation): In wtf: wtf.el:9:17:Warning: reference to free variable =E2=80=98it=E2=80=99 of the second: Symbol=E2=80=99s value as variable is void: it Expected results: byte compilation succeeds without warnings, second command prints "1". Note that if you change line "(let ((fn #'(lambda () it)))" to e.g. "(let ((fn #'(lambda () nil)))", everything works as expected. However, 'fn' _is not even used_ when function `wtf' is called with non-nil argument, which further conforms that the observed behavior is a bug. Another indication: when the function is not byte-compiled (e.g. delete file `wtf.elc' after the first command), it produces expected results. Function, of course, doesn't make any sense. It is a result of removing contents of real failure until it is as small as possible. Paul --000000000000a5e8d605d12a282c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Steps to reproduce:

1) save attached file as `wtf.e= l';
2) execute from command line:

=C2=A0 =C2=A0 $ emacs --bat= ch --eval "(byte-compile-file \"wtf.el\")"
=C2=A0 = =C2=A0 $ emacs --batch -L . --eval "(require 'wtf)" --eval &q= uot;(print (funcall (wtf 1)))"

Results, of the first command (b= yte-compilation):

=C2=A0 =C2=A0 In wtf:
=C2=A0 =C2=A0 wtf.el:9:17= :Warning: reference to free variable =E2=80=98it=E2=80=99

of the sec= ond:

=C2=A0 =C2=A0 Symbol=E2=80=99s value as variable is void: it
Expected results: byte compilation succeeds without warnings, second c= ommand prints "1".

Note that if you change line "(let= ((fn #'(lambda () it)))" to e.g. "(let ((fn #'(lambda ()= nil)))", everything works as expected.=C2=A0 However, 'fn' _i= s not even used_ when function `wtf' is called with non-nil argument, w= hich further conforms that the observed behavior is a bug.=C2=A0 Another in= dication: when the function is not byte-compiled (e.g. delete file `wtf.elc= ' after the first command), it produces expected results.

Functi= on, of course, doesn't make any sense.=C2=A0 It is a result of removing= contents of real failure until it is as small as possible.

Paul
=
--000000000000a5e8d605d12a282c-- --000000000000a5e8da05d12a282e Content-Type: text/x-emacs-lisp; charset="US-ASCII"; name="wtf.el" Content-Disposition: attachment; filename="wtf.el" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_kw6u7s8a0 OyAtKi0gbGV4aWNhbC1iaW5kaW5nOiB0IC0qLQoKKGRlZnVuIHd0ZiAoeCkKICAobGV0ICgoaXQg MCkpCiAgICAjJyhsYW1iZGEgKCkKICAgICAgICAobGV0ICgoZm4gIycobGFtYmRhICgpIGl0KSkp CiAgICAgICAgICAoaWYgeAogICAgICAgICAgICAgIChsZXQgKChpdCB4KSkKICAgICAgICAgICAg ICAgIGl0KQogICAgICAgICAgICAoZnVuY2FsbCBmbikpKSkpKQoKKHByb3ZpZGUgJ3d0ZikK --000000000000a5e8da05d12a282e--