From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Milan Zimmermann Newsgroups: gmane.emacs.bugs Subject: bug#59612: Incorrect behavior also with ${CONDITION} Date: Sat, 26 Nov 2022 11:19:08 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000097479805ee62010a" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="623"; mail-complaints-to="usenet@ciao.gmane.io" To: 59612@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 26 17:20:24 2022 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 1oyxuh-000AYf-Py for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 26 Nov 2022 17:20:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyxuW-0007cw-NF; Sat, 26 Nov 2022 11:20:12 -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 1oyxuN-0007ci-Sm for bug-gnu-emacs@gnu.org; Sat, 26 Nov 2022 11:20:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oyxuN-00082V-J3 for bug-gnu-emacs@gnu.org; Sat, 26 Nov 2022 11:20:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oyxuM-0002Kp-C2 for bug-gnu-emacs@gnu.org; Sat, 26 Nov 2022 11:20:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Milan Zimmermann Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 26 Nov 2022 16:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59612 X-GNU-PR-Package: emacs Original-Received: via spool by 59612-submit@debbugs.gnu.org id=B59612.16694795958965 (code B ref 59612); Sat, 26 Nov 2022 16:20:02 +0000 Original-Received: (at 59612) by debbugs.gnu.org; 26 Nov 2022 16:19:55 +0000 Original-Received: from localhost ([127.0.0.1]:41283 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyxuE-0002KX-Nm for submit@debbugs.gnu.org; Sat, 26 Nov 2022 11:19:55 -0500 Original-Received: from mail-vs1-f42.google.com ([209.85.217.42]:43737) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyxuA-0002KR-5n for 59612@debbugs.gnu.org; Sat, 26 Nov 2022 11:19:53 -0500 Original-Received: by mail-vs1-f42.google.com with SMTP id l190so6785070vsc.10 for <59612@debbugs.gnu.org>; Sat, 26 Nov 2022 08:19:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=JlT+2uFDUPvyAMcB0Emdw2SPmh84X2UZTQ5kj008PYg=; b=Q+Sb4sLYRoyQsRNcY04jBLNVRR8S0IdxnB/1NFEhxyIlQeX8TunkoP1ub91dw7nJWM yvRFlWnJlUn2DXlA0MkYTLhL9NlINad96ptHsD0N3oN/lJQa9/S5Ta3M9GaYVzy2oJTp 3bTY3YqPJLPwEU/zxqlL2YN6upOJOMk4nvykHcWVboV+Ex+g0WI7A2C6sBV+SOh3h3FZ Vkpusq9YYjtV7rUI6Y/IjAeboVr0pOfVqkttl6XUGqwdWkXFiz1uDNBUjRCtyZri31O8 zHh9OzQmPsjOr4LGpulDEUnpTJwRnTU5TxrKcUAsZnLiy6MiBXOEBTmNH6AW1UKzPFQv 3bPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=JlT+2uFDUPvyAMcB0Emdw2SPmh84X2UZTQ5kj008PYg=; b=rNXJJ23g/o7TufRvp2Vv+doO4kWgVIjv2SWhofYDgMR4ZwDpUEtQim673xEFSlD5lO +v/vh7wWAqrTcc2wLFdBkvZZkM8bK87Xccw9RvMSxJhUr4Q/LCJP8bn4XvCa86HS/VH9 ahC9CwV8R/Vv9aN7/Xpu0yVBtLV+GNaS9uuRDg7rszIzoM7BW9W0Q/+1x3amFaZazNSs uaj7GISIOqpPsdkea57v1qfgot3BpPoA4q6x11g+OaVZj24Kg3Vtd9nGHfTk7yyIqifA Eqpnur0n8jN1pAbSWfO0vbuZjIeoqwB99AZcbtWHJr0lkGcs1qxhBeQ+qcBczZslbq05 YhPg== X-Gm-Message-State: ANoB5pmwN2HuKf5sNG4IqPsFHqMJUWZvXqeo21YwYjyQrYbYrrue9dVf e/50qyD+LEqE5YpukwuvKB4Exh8+DHyo2z4gTMeVgRg+u6w= X-Google-Smtp-Source: AA0mqf45D2n0kb3UJ4uFtMf49qdSD6zHe/ZauNX5102K/Xz9COkEHUmI+bqKa0nRxlWcuUnZpje6n6TGxbSczz/Nag8= X-Received: by 2002:a05:6102:f9a:b0:3b0:8bc4:1600 with SMTP id e26-20020a0561020f9a00b003b08bc41600mr3112425vsv.4.1669479584448; Sat, 26 Nov 2022 08:19:44 -0800 (PST) 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:249113 Archived-At: --00000000000097479805ee62010a Content-Type: text/plain; charset="UTF-8" I should add that I realized using {CONDITION} alone is not a reasonable thing in my examples, as it uses exist status. In a real code, one would use ${CONDITION}. The modified script is attached below #####. However, the behavior is still not as expected: ~/tmp $ source ./conditionals-bug.esh It is 2 It is 3 It is NOT 3 It is 4 It is NOT 4 ###################################### # The behavior of conditionals depends on whitespace # Source this script to test it # This formatting works as expected; evaluates the "true" block. # Result: # "It is 2" # if ${= 2 2} { echo "It is 2" } { echo "It is NOT 2" } # This formatting causes a BUG: both the "true" block and the "false" block are evaluated. # I tried several combinations, it appears it the "false" block starts on it's own line, # it is no longer treated a part of the "if" expression. Which could be argued # is expected because there is no "else" that would define whether the second block # is not part of the "if" expression. BUT see next test # # Result: # "It is 3" # "It is NOT 3" # if ${ = 3 3 } { echo "It is 3" } { echo "It is NOT 3" } # BUT we get the same incorrect result if we place the whole if expression into {} { if ${ = 4 4 } { echo "It is 4" } { echo "It is NOT 4" } } --00000000000097479805ee62010a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I should add that I realized usi= ng {CONDITION} alone is not a reasonable thing in my examples, as it uses e= xist status.

In a real code, one would use=C2=A0= =C2=A0${CONDITION}. The modified script is attached below #####. However, t= he behavior is still not as expected:

~/tmp $ sour= ce ./conditionals-bug.esh
It is 2
It is 3
It is NOT 3
It is 4<= br>It is NOT 4


################= ######################
# The behavior of conditionals depends on = whitespace
# Source this script to test it

# This formatting work= s as expected; evaluates the "true" block.
# Result:
# =C2= =A0"It is 2"
#

if ${=3D 2 2} {
=C2=A0 echo "It = is 2"
} {
=C2=A0 =C2=A0echo "It is NOT 2"
}

= # This formatting causes a BUG: both the "true" block and the &qu= ot;false" block are evaluated.
# I tried several combinations, it a= ppears it the "false" block starts on it's own line,
# it = is no longer treated a part of the "if" expression. Which could b= e argued
# is expected because there is no "else" that would d= efine whether the second block
# is not part of the "if" expre= ssion. BUT see next test
#
# Result:
# =C2=A0"It is 3"# =C2=A0"It is NOT 3"
#

if ${ =3D 3 3 } {
=C2=A0 = =C2=A0echo "It is 3"
}
{
=C2=A0 =C2=A0echo "It is N= OT 3"
}

# BUT we get the same incorrect result if we place t= he whole if expression into {}
{
=C2=A0 if ${ =3D 4 4 } {
=C2=A0 = =C2=A0 =C2=A0echo "It is 4"
=C2=A0 }
=C2=A0 {
=C2=A0 =C2= =A0 =C2=A0echo "It is NOT 4"
=C2=A0 }
}3D""
--00000000000097479805ee62010a--