Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
	autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=from:message-id:date:to:subject:mime-version;
        bh=h/7cOJEdASNe+3OybpLLUwc7/8rxbiNBALsmpOfzsbg=;
        b=A3dEbY2+dbsDPr9P5aG6gY3QFr4Bx9cQlN6nXx+YJFa+ww0McO9YG5+psev+mX8g2y
         eBc3DEjBb6kbG4/jnj8UvhLnIUFT9Cagbn+QJSDqTy/8wjVtYKmtjVAAOFO4dGxhk/dS
         GeSSug9oI24y/xdZTvR8wuKogvtZ8Ybh/0EHGO2CyAfs1xVASAGa7MeEm75ruJAJVpiO
         KssUE9d1w3vrOAO9VeCxJ5u4e9paxAww2DPbt5eLKyaJtnomKPcOBtTdT5XcgWbBWdjK
         boXXM62cIPkswXHnhZdjJtjYFwaLsFCIBE3VR9F1WqOTvXLgAvXl6q86yZOS038+QNLZ
         WLHg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:date:to:subject:mime-version;
        bh=h/7cOJEdASNe+3OybpLLUwc7/8rxbiNBALsmpOfzsbg=;
        b=YjbGebJhqDFMAQlF04g9/9PeqrHqpeTgI4oVH7RPwS10j0sgJa5W5zXeSIoqqjKiBk
         AHHAvifRNCw4Zmpjoacmr+8G0OB1DCurflsjEQm4IDIEZE55IFnf/nfOJ0t1TJWVdZUi
         zILfZXeLliZD2+ECX7yRKShRxJWQMir1GqE24pUo85y7vP2krEX4eT8Ps/iZnKk/J1EM
         w7RQ1g5+GiFmK1orKhdUXeIQGryUW0MQ+GehAU2BqNKIAtHR90jkdSVioZwCFp217xuz
         2O2TPQdiaThLxjJgywj2kXdIscvB9QBA6Q3IpuDjLr7HTFtniTyiHUDqPapovdTvhqTa
         nfKw==
X-Gm-Message-State: AD7BkJJk8vhE6pMIGFL3xM3INNbtUmwAmUH8EdBI12HbzyGFXSjIzvp6ZsZgrshFX5OkRQ==
X-Received: by 10.66.154.233 with SMTP id vr9mr29102891pab.66.1457303248937;
        Sun, 06 Mar 2016 14:27:28 -0800 (PST)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160306142731.ZM3208@torch.brasslantern.com>
Date: Sun, 6 Mar 2016 14:27:31 -0800
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: zsh-workers@zsh.org
Subject: Bug in if... then if... parsing
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 38104

Reproducible at least as long ago as zsh-4.2.0.

Consider:

torch% x () {
function> if false
function if> then
function then> x=1
function then> elif true
function elif> then
function elif-then> if :
function elif-then if> else
function else> :
function else> fi
function> }
torch% 

Here it is without the PS2 prompts:

x () {
    if false
    then
        x=1
    elif true
    then
        if :
    else
        :
    fi
}

This should be a parse error --

torch% if :
if> else
zsh: parse error near `else'
torch% 

-- but instead it's accepted, the parser has somehow implied the
"missing" then/fi with a blank line between:

torch% functions -x4 x
x () {
    if false
    then
        x=1 
    elif true
    then
        if :
        then
            
        fi
    else
        :
    fi
}
torch% 

I was at one point able to get the parser into a state where this caused a
correct structure to syntax error because this weird implicit "fi" doubled
an actual "fi", but it was in the context of a larger function and I lost
it from my terminal scrollback by the time I worked out that it wasn't
something I was doing wrong.  It had something to do with "then" appearing
with other code on the same line rather than on a line by itself.

As far as I can tell this only happens when "if" immediately follows "then".
At first I thought the "elif" was also required, but no:

torch% if :
if> then
then> if :
then if> else
else> fi
torch% 

