zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: err_exit/err_return regression
Date: Tue, 29 Sep 2015 18:09:32 -0700	[thread overview]
Message-ID: <150929180932.ZM9288@torch.brasslantern.com> (raw)
In-Reply-To: <20150929205204.GA29608@Qliphoth.local>

On Sep 29, 10:52pm, Joshua Krusell wrote:
}
} Was in a hurry and didn't provide much context, but that was with zsh
} 5.1.1. I just checked out master and I'm still getting the same results
} on both OSX and Linux.

I can confirm.  If you also "setopt xtrace" you can see that it returns
at [[ -n '' ]].  If there is anything other than an assignment in the
"then" part of that "if", the bug does not occur, so I think this may
be in part a parsing/wordcode problem.

In the case with the assignment, when we hit line 1209 of exec.c [in
execlist()] the test (ltype & Z_ZIMPLE) is true, and eventually we
hit the same test at line 1252 and "goto sublist_done" which [here I
begin to lose track of the exact sequence of events] skips over the
execpline() call on line 1284 and therefore never resets lastval = 0
at line 569 of execif(), so we obey errreturn.

If it's a command rather than an assignment, we go through the
WC_SUBLIST branch instead, and everything works out.

I think what this boils down to is, "retflag" needs two values to
distinguish an actual return from an ERR_RETURN, the same way that
we distinguish interrupts from actual errors.  Patch below seems to
work for the "if" case, there may be other such cases.  Might want
to use bitflags and/or #defines instead of just 1 and 2.

Or maybe there's some other way to untangle the Z_SIMPLE case in the
exec*() chain and the patch below isn't needed at all.

Here's a cut-and-paste-able version of the failing example (before
the patch).  Replace "a=2" with e.g. "a=2 :" to compare.

source =(<<\EOF
setopt err_return xtrace

print $ZSH_VERSION
setopt

if false; then
    :
else
    if [[ -n '' ]]; then
        a=2  
    fi

    print foo
fi
EOF
)


diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 97c3370..691aaeb 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -175,7 +175,7 @@ pattern are loaded.
 With the tt(-w) flag, the var(name)s are taken as names of files compiled
 with the tt(zcompile) builtin, and all functions defined in them are
 marked for autoloading.  Note this does not otherwise change the search
-order for 
+order via tt(fpath) when the function is first called.
 
 The flags tt(-z) and tt(-k) mark the function to be autoloaded using the
 zsh or ksh style, as if the option tt(KSH_AUTOLOAD) were unset or were
diff --git a/Src/exec.c b/Src/exec.c
index da808d6..154bbb8 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1408,7 +1408,7 @@ sublist_done:
 			exit(lastval);
 		}
 		if (errreturn) {
-		    retflag = 1;
+		    retflag = 2;
 		    breaks = loops;
 		}
 	    }
diff --git a/Src/loop.c b/Src/loop.c
index 4def9b6..7d1528e 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -552,8 +552,12 @@ execif(Estate state, int do_exec)
 	    run = 1;
 	    break;
 	}
-	if (retflag)
-	    break;
+	if (retflag) {
+	    if (retflag == 2)
+		retflag = 0; /* Never ERR_RETURN here */
+	    else
+		break;
+	}
 	s = 1;
 	state->pc = next;
     }


  reply	other threads:[~2015-09-30  1:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-09 11:33 jsks
2015-07-09 13:38 ` Peter Stephenson
2015-09-29 15:43   ` Joshua Krusell
2015-09-29 18:54     ` Peter Stephenson
2015-09-29 20:52       ` Joshua Krusell
2015-09-30  1:09         ` Bart Schaefer [this message]
2015-10-01 20:32           ` Joshua Krusell
2015-10-04  0:26             ` Bart Schaefer
2015-10-04  2:58               ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=150929180932.ZM9288@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).