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 2FE082546E for ; Tue, 27 Feb 2024 07:48:49 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1709016529; b=TMq2K+HhQ9zhLfy9UagNK4I/Eh75nLKjLm+OyYrTS2LKmANp3uuwqojrGnMrPWWVolWCZsGUiM L8t/+cjhQYn6mMLBeemCHUEoakOzOGmy4clAj1wPUerNH8xDL6Bbvd6vxrs1NzrXMj98OEwXjM Aa8Sr6GTmW/CCBv0FN6dGZUXFkkZ89ZVmS02o/K3o6VdfJc2aKyVm8x04f0L/0rRyqHnlTQqA2 MB6UcxQ1O2q3OMXQlKCiribMcU5Xw1S9sCIEsqfseyqxlxgDDYnioKNJWAL4Vt135gd8zhAUFZ QiHXMSdWDLOn8MSmTlDKfLFk488022TmhqkXOH4nYyS+bw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay6-d.mail.gandi.net) smtp.remote-ip=217.70.183.198; 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=1709016529; bh=9d62vtfT6FYYs/Xy73xSusPVeFPbFndp6a0RxmS93Ho=; 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=HLVWTMRvuq3NvT3+48pprP2MP9icoPxu078iaXqiVAMDM7FgOuhtJ9a0eGps8fOZYHx1C0WgvE JbG8yHfZKo/6g17sRBU+0PAXYQuWSo5MT2+zQ3PKc9mcKdMpprISFV1JpUZRu2LWXpuRMmlPDh GVqmKgDwmzJBmjo1tqywy8NCe9drhRv3+0q2DGAAWY9ueNw1MPZDU3uBujPtIdgCX5Wqf794U+ uYW3XaXzZ5hOm3qssaWnpGEY/eRxylEJruqupSXLalRiPTn0K1i2GdzvRxkIBmuAF64eU/2Jgz sRc7qmxqDDZHsgK/dWASDY6H0fCEuX4x+63SBinKgAnB1w==; 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=5Z3apAZ2CmG1dabTP+KnYFAJ1kQa8L8X56tntC+HLD8=; b=ncPoT82EGunhmw7EGfnLiJL7vx NzXlcQo8V4rqtHDTJWF+3AFDnbIPV0e+Pt9/P+7pP16mKXkTuIgl8IA8UeoBxCRA70FaR8ig4iuU5 ImelhetrImdjH52s+M2FYtFKSQ7HWy4kV1/rAKpTvMDHFU1DXrZU1dpyjkI8xfF1iGi5am1QVBxHI oKxl01sD0uOGaGlozuz/3yv7oHES5PrZ0mKdpRceTnT1xY/0gimGSBs49JdWLq6P+PsEdvTSNGUrZ rxwRMPjDUICaT/ehyBROJL1g/Ok5H0HXLFKgS6EUMCpz38ZCtk86xt7lIfmJWAcDUsxvp4tcK5BZ1 kby2qzNw==; Received: by zero.zsh.org with local id 1rerGj-000C4v-0K; Tue, 27 Feb 2024 06:48:49 +0000 Authentication-Results: zsh.org; iprev=pass (relay6-d.mail.gandi.net) smtp.remote-ip=217.70.183.198; dmarc=none header.from=chazelas.org; arc=none Received: from relay6-d.mail.gandi.net ([217.70.183.198]:44685) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1rerG5-000Bl1-EU; Tue, 27 Feb 2024 06:48:10 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 0F29AC0006; Tue, 27 Feb 2024 06:48:07 +0000 (UTC) Date: Tue, 27 Feb 2024 06:48:07 +0000 From: Stephane Chazelas To: Bart Schaefer Cc: Zsh hackers list Subject: Re: Assigning an array to a nameref "placeholder" Message-ID: <20240227064807.xa77q6qjek77nekq@chazelas.org> Mail-Followup-To: Bart Schaefer , Zsh hackers list References: 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: 52620 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-02-26 14:18:03 -0800, Bart Schaefer: > Another one from the ksh93u+ gitlab: > > > nameref unsetref; unsetref+=(foo bar). This now produces a "removing nameref attribute" warning before performing the assignment. > > I would rather make this an error, but it's probably not difficult > either way. Comments? An error (or forbidding typeset -n ref=var without the =var part like in mksh) would make a lot more sense to me as well. The full commit log (see below) and https://github.com/ksh93/ksh/issues/678#issuecomment-1716507741 gives the rationale there for not doing so. In zsh, there's no backward compatibility to be considered as the feature is new, so it's our best opportunity to make it the best interface from the get go. Note that bash has been known not to always make the best design choices (including when copying other shells), so it's not necessarily a good idea to use it as a reference. Issuing a warning here would only make sense as preserving backward compatibility while at the same warning users against doing anything like that. commit ebfbe62863c36a7b99eb0aa9f831184cdde86f3f Author: Martijn Dekker Date: Wed Sep 13 11:25:28 2023 +0100 Fix segfault in unsetref+=(foo); add warning Emanuele Torre (@emanuele6) writes: > Appending a non-empty indexed array to an unset nameref crashes > with a segmentation fault: > $ arch/*/bin/ksh -c 'typeset -n ref; ref+=(); typeset -p ref' > typeset -n ref > $ arch/*/bin/ksh -c 'typeset -n ref; ref+=(foo); typeset -p ref' > Segmentation fault (core dumped) [...] > Appending an associative array errors correctly: > $ arch/*/bin/ksh -c 'typeset -n ref; ref+=([foo]=bar); typeset -p ref' > arch/linux.i386-64/bin/ksh: ref: no reference name For consistency, this commit makes all array assignments to an unset nameref (using either = or +=) succeed, but print a warning that the nameref attribute is removed -- a bash-like bahaviour. I think that this will cause fewer backward compatibility problems than making such assignments error out, since they used to succeed in some cases (e.g. 'typeset -n ref; ref=(foo bar)' always worked). It does mean the associative array reproducer above now generates a warning instead of an error. src/cmd/ksh93/sh/name.c: nv_create(): - After dereferencing a nameref, if nv_isref(np) is still true, we know it must be an unset nameref. In that case, add a check for c==0 (the value occurring upon var=(foo) and var+=(foo)), and produce a warning instead of an error, as argued above. Resolves: https://github.com/ksh93/ksh/issues/678