D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11761 - aa.byKey and aa.byValue are not forward ranges
Summary: aa.byKey and aa.byValue are not forward ranges
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2013-12-17 21:49 UTC by Vladimir Panteleev
Modified: 2014-08-15 10:34 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Vladimir Panteleev 2013-12-17 21:49:23 UTC
Currently, associative arrays' byKey and byValue methods do not return forward ranges (although this was the intention). The isForwardRange check fails.

The cause can be reduced to the following code:

struct R
{
	R save() { return this; }
}

void main()
{
	R r1 = void;
	static assert (is(typeof(r1.save) == typeof(r1)));
}

The compiler complains:

test.d(9): Error: static assert  (is(R() == R)) is false

Note the parens in "R() == R".

The problem goes away, if either r1.save is replaced with r1.save(), or the save method declaration is annotated with @property (despite the -property switch not being used).
Comment 1 Marc Schütz 2014-08-14 11:29:32 UTC
See also here, someone else got bitten by this problem too:
http://forum.dlang.org/post/safrphnyjhbryejzkbzu@forum.dlang.org
Comment 3 Kenji Hara 2014-08-15 08:46:52 UTC
(In reply to Vladimir Panteleev from comment #0)
> Currently, associative arrays' byKey and byValue methods do not return
> forward ranges (although this was the intention). The isForwardRange check
> fails.

(In reply to hsteoh from comment #2)
> https://github.com/D-Programming-Language/druntime/pull/925

Change the "Component" field because it's druntime issue.
Comment 4 github-bugzilla 2014-08-15 08:52:52 UTC
Commit pushed to master at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/38eee4cdf371ca9ab49962d2dfadbfb5785d7bcb
Merge pull request #925 from quickfur/issue11761

Fix 11761: aa.byKey and aa.byValue are not forward ranges.
Comment 5 Kenji Hara 2014-08-15 09:46:01 UTC
(In reply to Vladimir Panteleev from comment #0)
> The cause can be reduced to the following code:
> 
> struct R
> {
> 	R save() { return this; }
> }
> 
> void main()
> {
> 	R r1 = void;
> 	static assert (is(typeof(r1.save) == typeof(r1)));
> }
> 
> The compiler complains:
> 
> test.d(9): Error: static assert  (is(R() == R)) is false
> 
> Note the parens in "R() == R".
> 
> The problem goes away, if either r1.save is replaced with r1.save(), or the
> save method declaration is annotated with @property (despite the -property
> switch not being used).

The compiler behavior issue is now filed in bug 13293.
Comment 6 Vladimir Panteleev 2014-08-15 10:34:35 UTC
Thanks. Link: issue 13293