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 7A58A25601 for ; Wed, 6 Mar 2024 00:16:55 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1709680615; b=Sw8M3OHQaCyhyvc42jKvPiNRqt5pAEpShqoTtXFj6bPBeGYXCvJEO108hMq3s9ePm+mp8hogro nBS1tI56h1g0WxA9a4ZQptxou0NJKWYYYd6vy1G/lMw5/oHaQ/sDX5lsOwWPSj3pSdTxvWwRj8 CPV8UoLFHybPtsKqjRg6mh0NJ3qBU507oKDmyz3IZlnvTeRbEdxxyrr+87og6CEDTZ8vvJ0DBK 8Y65FvUNdTn2JH6W4BAjLEYPMbsubemle3nDZKHD9Z+JPYoP9PzN/7DEfgQSMF5lfUSLApp1yK QXVpmj5XTaqAbNfnqrc2qhEP4VtDMu1EjfpAEfJpN+yRNg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f46.google.com) smtp.remote-ip=209.85.167.46; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1709680615; bh=WUBJdobm7CUNAp40/8fitzxIvBGsIMIU6l1Xea1GkBw=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature:DKIM-Signature; b=A4/t5147OGsylQWbtjuKCPEWLyMZ+KVawpN/3FIJWtkxnMlAPPzB/XshibBOj6uossb1TZYnah VZFppEwqgcQk86/e4uar4WzSZLk7ild/ZdhXDkTo4NlTVMVkh2HXhYEuiuOyDTmp1+4OGyz6QI NqgY+fI5Vskz9pGTZLWOBgyUlqdHj0MMlVO6og/5J0XMASYoDDckH+iY0g9jHj9kAsXNWJrU4G 8cUl9BYSChp9AV/jehLYdvswhbxJLr4Mi42dipUg7xh+5HlwckobOevQrAX/WES8fil028Ajql yB0tkTDdVEeE5eStZHTSmU6gSN9bxIOEUY/eLs/FAHrRCw==; 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-Transfer-Encoding: Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=TjXglTdLKgFN9lHKOXzJ7gyhIkJTd0lFI6AfF2aOTdU=; b=l5G+fcIRada070Vkw2v1LmkYi0 Zi9XLFfWYvviEKS5EE2sBRh7dtP8/ojJ5v10IyMCbFs/RTYs2oRaLdwl3bCbKJeXtdgzssJUGY+4I LBc2oh7hYpfr+LrggFUKIKlm0A0rlNoi23uNe+kyGNqKdpnUYksQU7rfk57lqXRMQ8U9U9CsOKFHr ZKTI03PhEGgEGXj822G5imw96VyUi7GafQGtkcFNCGCF3Bqxx9Bpj8Vy1yx+joE8Ij9dFRyo0BoeF 2SPUGGR+C1H9C8XckIwdcZsC74pcIkPTxKtLThiYfoOlGKubNqtX+M4lg1vyBwuiiQRkrVqiaJH8h XWZOAOIQ==; Received: by zero.zsh.org with local id 1rhe1n-0006ZH-FR; Tue, 05 Mar 2024 23:16:55 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f46.google.com) smtp.remote-ip=209.85.167.46; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-lf1-f46.google.com ([209.85.167.46]:47131) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rhe1W-0006HU-6E; Tue, 05 Mar 2024 23:16:39 +0000 Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5101cd91017so8620545e87.2 for ; Tue, 05 Mar 2024 15:16:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1709680597; x=1710285397; darn=zsh.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TjXglTdLKgFN9lHKOXzJ7gyhIkJTd0lFI6AfF2aOTdU=; b=OmiJ9CaWcOND/m0KXzWXHSNCjKlbfOdH8syBDX27OTAV/FnBl7FFv+ma8rrz47Dse0 7QMY8ucEfRSgCO6dMTXmwDgC6h/qQq833Rcp38+/VckZSaBjhtWmQckaKO9x/bURZnU6 CdGRCthfBASamci14T9JMf+UxLfGvFXLoY5h/97A+MoXtRVxnD3p59Ga8IhbEn6hoaLA vaAH7elWVrsOWGe4ZVH7TuioAZ/6/eHpRQEGQWCCu4tjz4AcXyqxIevvJh5DreMxK/6D 2muwzj9WhitUFibZ7Sy7YIk0j6XFJ6gFM6MfGhQe0FFUQZJULWg+RD/Jtyf5aeYUPJhC lvXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709680597; x=1710285397; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TjXglTdLKgFN9lHKOXzJ7gyhIkJTd0lFI6AfF2aOTdU=; b=TYXHEb0oTFcS/w0fg0qbRVAR5y6/Yf9it5gcQqgEwaGr0puS+TnOsvzPu3D72K2yRD s5vzgSxhsStb/9hoAvVcheAHhggd+6SF8PWPwrZXqo5aheY36z6+QA0a6ZYTWcaPZ7rF UQItDmpALCFPmNtv6bV567J9cZuN/USSZOMdr5C57ZQipaoiJWDPlVSqpitGt52DGwRq gS1jdLqZrTdwP18G7lfR38UOOpjtJ9I9DnKSiPQdWvRKL/oRrJYFv3MYrvboHZgKxdT2 5EIddNmsKxgn2PqpW5YZtcSZ86Hf8ClRYIiRmxV7a9tb9JCqaMgVSAfj8sY9roKBnaPY 4+XA== X-Forwarded-Encrypted: i=1; AJvYcCXhrRAJN2tRtasuOzE5a03tFggdcjIxxjfyOj2LxRz3p0LlsQzWa3V2t2fDk1JiUZSE8Dm56wAvuIR7NxbCjc/SteyE X-Gm-Message-State: AOJu0YxhBrfhU8GE2cN1edkjxitVrsEaC0wqkDY6AeGx8pLj2wbgVkBr EDYODMrF+lG6o+VnOXNz/OhbQSYyfkz4yho1j+Kt6IPS+b09arKNO/u2bDDpbq67kHZZi0+6Rhp 12LMhMpyJ53doSUtPuctsFmDf/n7n68L1aVjSM5x5J8MmArBJ3Q== X-Google-Smtp-Source: AGHT+IHtGmK1Pxht0FZHogkCc29KkilSqjNWxFhuB5ApdL0BVjIQdMn1d3PohB23iSKzGx9F+CmlPfdvLcG3O0IJFAs= X-Received: by 2002:ac2:494d:0:b0:512:b517:982 with SMTP id o13-20020ac2494d000000b00512b5170982mr1976912lfi.20.1709680597139; Tue, 05 Mar 2024 15:16:37 -0800 (PST) MIME-Version: 1.0 References: <20240304062914.kn6wquvgog3lefom@chazelas.org> <20240304193409.lv725ah6eifiazzx@chazelas.org> <20240305081859.r3qwiyduk2wgkdby@chazelas.org> <20240305193840.vvixetyn6vfnbir2@chazelas.org> In-Reply-To: <20240305193840.vvixetyn6vfnbir2@chazelas.org> From: Bart Schaefer Date: Tue, 5 Mar 2024 15:16:25 -0800 Message-ID: Subject: Re: [PATCH] Fix crash on unset-through-nameref To: Bart Schaefer , Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52691 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 Tue, Mar 5, 2024 at 11:38=E2=80=AFAM Stephane Chazelas wrote: > > 2024-03-05 10:42:18 -0800, Bart Schaefer: > [...] > > > where namerefs are just plain scalar variables containing the > > > name of another variable (or other lvalue) and having the target > > > variable resolved any time the nameref is assigned/referenced > > > > That is in fact exactly how it works, with the addition now that -u > > makes it skip upward one scope before resolving. > > Well, not in the: > > $ ./Src/zsh -c 'f() { typeset -n ref=3Dvar; local var=3D1; echo $ref; }; = var=3D0; f' > 0 OK, yes, there is one extra attempt to resolve at the time of declaration, and it "remembers" the scope where it completed the resolve and always goes first to that scope again. > But is IMO somewhat inconsistent with: > > $ ./Src/zsh -c 'f() { nameref ref=3Dvar; local var=3D1; echo $ref; }; f' > 1 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 think you're referring to the difference between var=3D0; 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=3Dx would work if you never declared anything, and consistent with ${(P)ptr} / ${(P)ptr::=3Dx} 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.