From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 17F9325378 for ; Wed, 6 Mar 2024 19:21:26 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1709749286; b=TU5e6QAa2kuLYw1yeL6Fz5DBAOJE3eBm5aJ3Op1BN69cFGXyxIQtrBYIhRv36YMl7+JmFwoNoQ OGQM0ptHITLqOY4UparmnClOfNhToekltOAEWC0xneL7Pt0KOVZ79Wm2Hbm8HbAXE0XvW8Rgz4 A87HaaTV0lNPEyXQM753Pr8JmQ66lv72BSSOKy3jRLbNxlrp+q9BegUEUOnxJKw0U2a13yU1O4 ajnqq2/wyG+YcCCpQPt7wTUcU61Ne8TlfiByILZldPiahWRYzrf7K3BM1yZUObJ1kk0DzuDwbg I1XavisQ07iKCNEsarWA8gL/6PsWKBgl4PK7x2Qa9clg1A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay9-d.mail.gandi.net) smtp.remote-ip=217.70.183.199; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1709749286; bh=vVdBBxYWXLHB6oog8+gdX04qMXGU/UqY+WYMtmc1hGE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature; b=pl+E0x5SdPD5Ak6/gr5i6tYb/GYno+uNgyZbqp+labFZsQkw6a4IPpBGsviKBpGaR1/QPk9ntX hZB6H/Y5VC9pQsEkZ4eMPWXgMACkbM7zM3VLBVe0hUE2zaQt06oqiVaXJ4l1Tz1/A1dQHeoYAq D8vQgcEWL1L0dg+06utoX8nyHsE+KTPFNSdzs0NzdZmVFBAcTmZZdVM09ZxYTysHOmRd/wUMk+ /GrFenk5bac0QTOPnmJCppZML2GYtcp8hETeyDUvz7ALwqkC2rJW+M0RwVh3Ceu7bT5bQ3ix8l loFmGs8mq3hFneITGHVhzB5ekWSbcYbFJw2yjH0VYOdaag==; 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:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=rjaukr2kVP7UA0iJiTNcQKrbmnEiDAX5lMDfBTN3wTo=; b=Cy8ZdTkQpafh+hLvlhhtGnKngY ImkhgS8N/yn4zi1aTqTSDQIqx5gZZPSWvSbK45BB8bk2HJLaSZldgfuEzVhZrE146/3QBPmyj2J5X VTHJ9FpPWAs9TXYnCMSXtSWfj/LO1EHyjhbSv8YFIccm7QlKgx6NHYVexQVxEAOgDFvjnd97RLhfZ Y6crQoLY3z06FIqolHe4fAB9LkFfjDjwLk0bN48l3T43teRCLsiIM+x5asOzURt/JULS0/KzmkkSo H3txAtC2liZ+jAcgtDsEOwTgJY7NV3mGufMh5kQTNMCTLB0je8Altib4LUGhY/fawqn8z68Kl0QwG lv6uQFkA==; Received: by zero.zsh.org with local id 1rhvtO-000KvF-Fz; Wed, 06 Mar 2024 18:21:26 +0000 Authentication-Results: zsh.org; iprev=pass (relay9-d.mail.gandi.net) smtp.remote-ip=217.70.183.199; dmarc=none header.from=chazelas.org; arc=none Received: from relay9-d.mail.gandi.net ([217.70.183.199]:38051) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1rhvt8-000Kcs-Mm; Wed, 06 Mar 2024 18:21:12 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 937F3FF804; Wed, 6 Mar 2024 18:21:09 +0000 (UTC) Date: Wed, 6 Mar 2024 18:21:08 +0000 From: Stephane Chazelas To: Bart Schaefer Cc: Zsh hackers list Subject: Re: [PATCH] Fix crash on unset-through-nameref Message-ID: <20240306182108.tf7qmtcdiykej4uv@chazelas.org> Mail-Followup-To: Bart Schaefer , Zsh hackers list References: <20240304062914.kn6wquvgog3lefom@chazelas.org> <20240304193409.lv725ah6eifiazzx@chazelas.org> <20240305081859.r3qwiyduk2wgkdby@chazelas.org> <20240305193840.vvixetyn6vfnbir2@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-GND-Sasl: stephane@chazelas.org X-Seq: 52694 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: 2024-03-05 15:16:25 -0800, Bart Schaefer: [...] > Sorry, your example is confusing me. "nameref" is only available when > the zsh/ksh93 module is loaded. What's actually happening here, and > why do you never use -fc to prevent dotfiles from being read? I hadn't realised -f also skipped ~/.zshenv, I thought that one like /etc/zshenv could not be skipped (and why I always leave it empty as it also affects scripts). Should we also use #! /bin/zsh -f- shebangs in scripts? > I think you're referring to the difference between > var=0; f > and simply > f > In the latter case, "the scope where it completed the resolve" is the > local scope because no parameter in a surrounding scope exists. If > you assign to such a nameref, it "goes first to that scope", and if it > still finds nothing, climbs up to global scope (because implicitly > "finds nothing" at any local scope means there can't be that name at > global scope). > > It's consistent with how $var / var=x would work if you never declared > anything, and consistent with ${(P)ptr} / ${(P)ptr::=x} when ptr is a > plain scalar. The difference is when the ref has already found > something, which seems like the intended difference if you're using a > reference in the first place. My point is that if it means the: assign() { typeset -n var=$1 local value=$2 var=$value } doesn't work for assign var value or assign value something And we need to work around it by doing: assign() { typeset -n _assign_var=$1 local _assign_value=$2 _assign_var=$_assign_value } (Yes, I know we can always fo assign() eval -- $1=\$2) Like we do in bash/mksh or when using (P) or eval... then there's little point trying to be smarter in the var=; assign var value value=; assign value something cases. You may say there's no harm in doing so, I'd agree there's little harm except - it makes it a bit inconsistent - it may trick users into thinking they can get away without using namespacing. In any case, I'm not against being smart in the second case, I just wish we could get away without the namespacing (like in the zslurp case which started that whole discussion). -- Stephane