D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6986 - SortedRange[x..$] fails with unidentified __dollar
Summary: SortedRange[x..$] fails with unidentified __dollar
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-21 22:35 UTC by Jerry Quinn
Modified: 2014-01-26 09:11 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jerry Quinn 2011-11-21 22:35:06 UTC
dmd 2.056 Linux x64

import std.range;
void foo(int[] buf) {
  auto bufsort = assumeSorted(buf);
  auto r = bufsort[1..$];
}

~/d/dmd2/linux/bin64/dmd -c range.d
range.d(5): Error: undefined identifier __dollar
Comment 1 Jonathan M Davis 2011-11-21 22:57:17 UTC
Technically, this is an enhancement request, not a bug - though it's certainly a very desirable enhancement request. assumeSorted returns a SortedRange struct which wraps the range which was passed to it. SortedRange does not define opDollar, and at present, IIRC, opDollar hasn't been working correctly. So, it's not possible for SortedRange to define opDollar, and there's no way that your example is going to work. However, it looks like there was a commit made to dmd about an hour ago which relates to opDollar ( https://github.com/D-Programming-Language/dmd/commit/aba0f773416e1d45d227159cb22ad0e26bb980c0 ). So, it may now be possible to implement this.

But the short answer for why this doesn't work is that $ doesn't yet work for anything other than built-in arrays, and assumeSorted doesn't return an array, even if you pass it one (and it would defeat the purpose of assumeSort if it did return an array).
Comment 2 Jerry Quinn 2011-11-21 23:06:36 UTC
I'd think the simplest solution would be to do the same rewrite that happens for builtin arrays, i.e.

x[p..$] => x.opSlice(p, x.length)

Then no opDollar is needed.
Comment 3 Jonathan M Davis 2011-11-21 23:13:04 UTC
It doesn't work that way. opDollar is what's supposed to be used. I forget all of the reasons why, but I believe that it has to do with cases where opDollar would do something more complicated than simply opSlice(p, x.length). opDollar is more flexible for some set of cases, but they're not the sort of use cases that I normally think of, so I don't remember the exact details at the moment. I'd have to go digging through the newsgroup archives for discussions which related to it.
Comment 4 timon.gehr 2011-11-22 03:49:48 UTC
The rewrite from $ to .length does not work if a range has no predetermined length (eg. if it is infinite or corresponds to an input stream)
Comment 5 Peter Alexander 2014-01-26 09:11:41 UTC
Fixed in 2.061

https://github.com/D-Programming-Language/phobos/pull/365