Bug 3470 – [tdpl]: .length should not pop up inside indexing expressions.
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2009-11-03T00:03:00Z
Last change time
2015-06-09T01:26:56Z
Keywords
patch
Assigned to
nobody
Creator
clugdbug
Comments
Comment #0 by clugdbug — 2009-11-03T00:03:10Z
Found this in the "thermoplyae" excerpt.
----
PATCH: dsymbol.c, ArrayScopeSymbol::search(), line 1062
//printf("ArrayScopeSymbol::search('%s', flags = %d)\n", ident->toChars(), flags);
- if (ident == Id::length || ident == Id::dollar)
+ if (ident == Id::dollar)
{ VarDeclaration **pvar;
----
I have already made the changes to druntime (svn 192) and Phobos (svn 1319), so that they'll pass all unit tests once this change has been made.
COMMENT:
From the changelog for DMD 0.115 (Mar 7, 2005!!!):
$ can now be used instead of length inside an array's []. It represents the length of the array. This is a trial feature, if it works out then these will happen in sequential releases:
1. length will become deprecated inside [].
2. length will be removed as the implicitly declared length, and it will be just another identifier.
Comment #1 by clugdbug — 2009-11-03T03:41:38Z
Note for Walter: This is the list of test suite files which are using [length] and need to change to [$]:
test16
test23
test34
test42
template4
template6
hospital
stress
lazy
variadic
testfile
Comment #2 by andrei — 2009-11-03T05:15:37Z
Great work, Don! Since you're there and the code is fresh in your mind, I suggest you operate these two additional changes that were discussed in the newsgroup several times:
a) In single-argument index and slice expressions, rewrite $ to __a.length, where __a is the already-evaluated array being indexed/sliced.
b) In multi-argument index and slice expressions, rewrite $ to __a.lengths!(n), where n is the compile-time argument position where $ appears.
Comment #3 by clugdbug — 2009-11-04T12:16:12Z
(In reply to comment #2)
> Great work, Don! Since you're there and the code is fresh in your mind, I
> suggest you operate these two additional changes that were discussed in the
> newsgroup several times:
>
> a) In single-argument index and slice expressions, rewrite $ to __a.length,
> where __a is the already-evaluated array being indexed/sliced.
>
> b) In multi-argument index and slice expressions, rewrite $ to __a.lengths!(n),
> where n is the compile-time argument position where $ appears.
Actually, the 'opDollar' problem is not very similar to this one, so I'll create a new ticket for it. I've had a go at it. The difficult bit is that currently '$' turns into a symbol, but it needs to become an expression, and it needs the 'this' pointer, which isn't in scope. I can get around this by creating local variables to hold the various values of $ for each dimension, but I'm not sure if that's the right approach. Still not working, but close.
Comment #4 by dfj1esp02 — 2009-11-06T02:40:23Z
Why? Is it because compiler doesn't detect ambiguity/shadowing?
Comment #5 by andrei — 2009-11-06T07:00:23Z
(In reply to comment #4)
> Why? Is it because compiler doesn't detect ambiguity/shadowing?
There were discussions in the newsgroup in the past. In brief it is bad practice to have the language introduce identifiers automatically in select places. Essentially that makes the identifiers de facto keywords because you shouldn't use them as regular identifiers - they could always be shadowed.
Searching the title of the newgroup for "length" shows many related conversations.