Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Qmail-Scanner-Diagnostics: from mail-pa0-f68.google.com by f.primenet.com.au (envelope-from <schaefer@brasslantern.com>, uid 7791) with qmail-scanner-2.11 
 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1.  
 Clear:RC:0(209.85.220.68):SA:0(0.0/5.0):. 
 Processed in 0.142172 secs); 12 Aug 2016 23:04:21 -0000
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID
	autolearn=unavailable autolearn_force=no version=3.4.1
X-Envelope-From: schaefer@brasslantern.com
X-Qmail-Scanner-Mime-Attachments: |
X-Qmail-Scanner-Zip-Files: |
Received-SPF: none (ns1.primenet.com.au: domain at brasslantern.com does not designate permitted sender hosts)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=from:message-id:date:in-reply-to:comments:references:to:subject:cc
         :mime-version;
        bh=LPXo6SeI70AD9eev7NyHuOkvpJE5LCmtPAIpqY959Mk=;
        b=Qk6Omb2x+F5U9TmdINmCFCrFel1aTz6hRa9JI+5O2FtByg4XrE00GVtpzg6Q4gyxD4
         f1o6JnVQKTj6dsp8uIKnj1aA55k5QDInJJfCB0EykvalFxrgqqis5cWaYZ9xTSU6V/hu
         2qAlXnYa1jKvqTxPnzqXHm7PW+7vxLf0YScA+Pl16fNb6qhkX+5LT4fDq9XquL4OzxEN
         aupqLMPNb1gbE7aYw2OE+cEynjZSCwHgRynuNkrP2Whs6qOQVZLkd+RUgLdmB7FVUluF
         pjLZXerFnVt698Up39bfD/KOz0uC+X4cFGd5Fvm6hgEtu0ooGElXvX/KTjXonk+V5zBO
         sBIA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:date:in-reply-to:comments
         :references:to:subject:cc:mime-version;
        bh=LPXo6SeI70AD9eev7NyHuOkvpJE5LCmtPAIpqY959Mk=;
        b=gTU2sdOQCZpQwiIM/s4x1JYYmvi0UconQ3HcwO72rFpF5HWopdXNxZuV5xOhKq/BMw
         6Ebink3I0YD/cuK7vipvS9ArxFMBIX31fkHMs12a6wYJO553kZq9jIlD1gL9UwP5POQB
         7WDG/GXLWWXuwa24KLWSiwHLLPbvjTC9LI7vZCTAm3dQLSha66eiKhUJP0FlzGUmpgLo
         U3EikPSbSmy7rRqGrsXIvmIsDlDuA6nhjKcjuqyVlNPKIR/cfeGlf3B54MFnJNtemgHU
         r5+6OoP2PQRYNmGHqo23mfYsWjbbL/bTTtjKS66J24X6VdrfKI3BkjfBn4bZPV2xcj7j
         igLQ==
X-Gm-Message-State: AEkoouspJ47Xaab7tqObb6a1FBSAKD/9KJ9DZZ5mjMasTd63yBIWiRBZPAnnf3KwCato1w==
X-Received: by 10.66.54.229 with SMTP id m5mr31105888pap.91.1471043048605;
        Fri, 12 Aug 2016 16:04:08 -0700 (PDT)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160812160407.ZM30052@torch.brasslantern.com>
Date: Fri, 12 Aug 2016 16:04:07 -0700
In-Reply-To: <DC080C9F-3A3D-4B68-BE29-765F7898647F@larryv.me>
Comments: In reply to Lawrence Velazquez <vq@larryv.me>
        "${#${(A)=name=word}} behavior depends on number of elements" (Aug 12,  6:11pm)
References: <DC080C9F-3A3D-4B68-BE29-765F7898647F@larryv.me>
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: zsh-workers@zsh.org
Subject: Re: ${#${(A)=name=word}} behavior depends on number of elements
Cc: Lawrence Velazquez <vq@larryv.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 39035

On Aug 12,  6:11pm, Lawrence Velazquez wrote:
} Subject: ${#${(A)=name=word}} behavior depends on number of elements
}
} As I would expect, ${#${(A)=name=word}} expands to the number of
} elements in array "foo" after assignment.
} 
} However, if "foo" ends up with just one element, the expression expands
} to the number of characters in that element.

The value of ${foo=right-hand-side} is the value of right-hand-side,
after applying all the expansion flags, not the value of $foo.  Thus
${#...} counts right-hand-side, and the shwordsplit of a word with no
spaces is a scalar, not an array, so the number of characters results.

However, this turns out to be ridiculously easy to change so that
the code matches the implication of the doc for ${NAME=WORD}.


diff --git a/Src/subst.c b/Src/subst.c
index 99e1650..c61551b 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -2897,6 +2897,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 			    aval = paramvalarr(pm->gsu.h->getfn(pm), hkeys|hvals);
 		    } else
 			setaparam(idbeg, a);
+		    isarr = 1;
 		} else {
 		    untokenize(val);
 		    setsparam(idbeg, ztrdup(val));
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 460a841..37166fa 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -82,6 +82,11 @@
 >wasnull2d
 >wasnull2d
 
+  unset array
+  print ${#${(A)=array=word}}
+0:${#${(A)=array=word}} counts array elements
+>1
+
   (print ${set1:?okhere}; print ${unset1:?exiting1}; print not reached;)
   (print ${null1?okhere}; print ${null1:?exiting2}; print not reached;)
 1:${...:?...}, ${...?...}

