From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 32283 invoked from network); 1 Sep 2021 16:12:52 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 1 Sep 2021 16:12:52 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1630512772; b=Ml0bfyQS099EKrY4MpvaE7lHV+/cZy47E4WPDvYK5BHlONnuqfTykM4+RwYZzBLDjc2+mzwjo1 lOY9XIvKv25eErK8tL1tan7nZua3eOw+yq/3aREuRHFU6/wj1/wb9RxUZl9HcNg1vJlCvmcMr5 2M0KtSicE5eCHW/yBNdVZCXa7mTyxsqlmWuFShAy2QeGafuw1GDZQ2EJQDB1BxS9Ddwow00Hey 2+E92pe0B8+SHxmZ/U/tau5duiqaAG6FcHBjl5iQaNOGl75QAkClUIDi1jxt6NnwwsJ6uwn5go hWIj7hHaXi78gBSigEAuisD9t0TMD2xv17SvpWgYLqSKmA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-vs1-f44.google.com) smtp.remote-ip=209.85.217.44; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1630512772; bh=lFuSPAsKlP0Zl6CxIgYn2Gcow7P2+OhYEWekNmckwwU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=ZqXzSwypQ1ObDTIqA67lNMqSGKPLqG4U6Z6ZvUHJOJtDrEaG1Pw4ndKpM+0jW2C3Crk4AX7X8i eJ5TTBLdQtm83vxvh2WdNe3kLwyHiMvaT+c0rsGKmu0UO3kpvNKvkGLRk9zx2w43jA38x6VmEJ uYt2WlvI8j3LQ4NxFv7GsoUB7VA46M5itPQG9mvlVSiPYMFv9M13fi0uOTwcmJl8M7kgqR+ut0 PycmU59Ky8ZsksnwjQB9E97j+hhe5oWI+SNlqjlxljakbq7GW78hVGW7JrxPkPol8RbDp3hg2z Zw5LsfA4xkF+C+TtAQXG8Sox9Reg5WcHmz7fatqXDMEByg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=elT5ZZBiwIcCm7fYOSojubtneUA/RHicUn5DmGJKhDs=; b=TszsvxxaDBHR+Mf2E154OFIpoy 0rWiqFne7cYk2K44WLn8VhpOa1N9LlbrrhsPdvaxssW95XIiwgiLVGppm+RtIeEpsM7SSNZ5GIjFE KNO+/jLInwKsg7LCvEhX1GCed7jYDo8DqHDLVgAMjCEH64tJ+rX5d1Mbqehw1IP30ae9gyY6VvmK2 O2R86tnvU6PH0HNZsxJVb+OToolhh6NRGAA9MQJRfHY1VidCL6uLfBZndvGvxuVsd8SYN0BkFyYZf up5Ri/08mFcw6DJVuHDqOQzPcjBqmzKKzuenXxutjhdYwpkOrLcFPCm/K56HqVnDUWQLpYbad1kiS vebYs+vw==; Received: from authenticated user by zero.zsh.org with local id 1mLSr6-0004Cp-GS; Wed, 01 Sep 2021 16:12:52 +0000 Authentication-Results: zsh.org; iprev=pass (mail-vs1-f44.google.com) smtp.remote-ip=209.85.217.44; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-vs1-f44.google.com ([209.85.217.44]:46738) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mLSqn-0003v4-KH; Wed, 01 Sep 2021 16:12:34 +0000 Received: by mail-vs1-f44.google.com with SMTP id s15so195825vst.13 for ; Wed, 01 Sep 2021 09:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=elT5ZZBiwIcCm7fYOSojubtneUA/RHicUn5DmGJKhDs=; b=MS5ksy6BKNOdpZrWAeEmXxrcRSA0uQ9leGb1iBAHgh9RJOR+LiqHvDlIeohfHRaXpM ngklbq8+fAM4vYMpsJhD7X5tvhn62g+1rfSouqUT5QI7qvQKcZG0M6uzgbpZAU/+QhCr DKmSxJdlwr51w6efxoylFdveZ4IDLqxUdfj5Oba0OMQy5UXGOt4mTLgfqfSJAHHGkj+9 EOoa2Av8R0PCpv/r2GJANcAP41RsnKBJGMFLCI9p8YbpfQBJzjVKvpL0AKNNFYsPSKRa PS1rxuE6QJvE2weJ/ABYlVtH2GH/11QUED2RCmyWuH4uxu4YO/b8EOXDy2iAE6RjyMLA 6wOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=elT5ZZBiwIcCm7fYOSojubtneUA/RHicUn5DmGJKhDs=; b=ELkoXW7qbTiZpQasixG195DhuvoBSkDh4UvgGo9fm8FETjvk3kLhSL4deqUcklK347 TJgZ9G34MuKvlrv4se4aPdbCrQts7qn9zTZsnvaiBI4wp8uxzSbMeP96XTpCeFp/Z7rS F1NhGAiKu9dEM3qpcRhPuCk81LyR0ZyqBh1Il8CdG8v8RXx6cS8eu00G3q+4Cq/2r7s/ dWer+7+xDk8voA6ea5UVeQZ9u2oqKniOa/Q6wnJkTW/ubSyk47gqXIFMzylSLkHI5TWi WLDAtiYWiOMtGsPNeDiJ2d1G6Npa8w8ZLE8uXBzOsGKsNHy91hYRBp0oQRrJER1MvvzK jlTQ== X-Gm-Message-State: AOAM531NSbY9veO3Sn6GVPdQ2CRk+QqX94CCV+cqsUQvvRqfejYfXDom YlrszGIYpZiJ+YyI5T9iICrhmx/xiYs7AMnjN6w= X-Google-Smtp-Source: ABdhPJwgYeKHwVMIlyQ5SILUgAYKGY3BGXq7eQkhLKRQk+hRQisBuQVgBpvwzPZ5Y4Q4f0tL5uW6X7GXfe9sx5aofh0= X-Received: by 2002:a05:6102:3f12:: with SMTP id k18mr267640vsv.14.1630512752588; Wed, 01 Sep 2021 09:12:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Marlon Richert Date: Wed, 1 Sep 2021 19:11:56 +0300 Message-ID: Subject: Re: [BUG] zsh/param/private scoping error To: Mikael Magnusson Cc: Bart Schaefer , Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 49355 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On Wed, Sep 1, 2021 at 7:03 PM Mikael Magnusson wrote: > > On 9/1/21, Bart Schaefer wrote: > > On Wed, Sep 1, 2021 at 4:51 AM Marlon Richert > > wrote: > >> > >> % () { private tst; () { tst= } } > >> (anon):1: tst: attempt to assign private in nested scope > >> % > >> > >> This is not how one would expect private variables to behave. > > > > But it's how variable scoping behaves in the shell language. If I do > > > > % () { local tst; () { tst=foo } } > > > > Then it is the tst in the surrounding scope that gets altered, not the > > global one. If the inner function is INTENDED to create a global, it > > should be using "typeset -g" explicitly. > > This seems weird to me, since private is stated to be "used to create > parameters whose scope is limited to the current function body, and > not to other functions called by the current function." If the > private parameter is not in scope, then any called functions should > behave as if it is not in scope, ie automatically create a parameter > scoped to whatever level is above the one that has the private. > (technically speaking, this is probably hard). Also note that when _reading_ variables, the `private` keyword already behaves like this, that is, the private variable is out of scope for the inner function: % () { ; private tst=bar; () { print tst=$tst } } tst= % % tst=foo; () { ; private tst=bar; () { print tst=$tst } } tst=foo % > If private parameters > are only compatible with code that runs without warnings under setopt > WARN_CREATE_GLOBAL, then we should document this. That would largely defeat the purpose of private variables, wouldn't it? :)