D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7489 - A problem map on AA.byKey()
Summary: A problem map on AA.byKey()
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-12 12:19 UTC by bearophile_hugs
Modified: 2013-11-26 22:02 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012-02-12 12:19:39 UTC
I don't understand what's happening here, sorry.
This isn't a fully minimized test case.

This program compiles (DMD 2.058beta2), with the first call to foo() commented out:


import std.algorithm, std.typecons;
void foo(T, U)(T[U] aa) {
    map!(x => Tuple!U(x))(aa.byKey());
}
void main() {
    int[char] aa1;
    //foo(aa1);
    int[int] aa2;
    foo(aa2);
}



If I comment out the second call to foo() it compiles still:


import std.algorithm, std.typecons;
void foo(T, U)(T[U] aa) {
    map!(x => Tuple!U(x))(aa.byKey());
}
void main() {
    int[char] aa1;
    foo(aa1);
    int[int] aa2;
    //foo(aa2);
}


But the whole program doesn't compile:


import std.algorithm, std.typecons;
void foo(T, U)(T[U] aa) {
    map!(x => Tuple!U(x))(aa.byKey());
}
void main() {
    int[char] aa1;
    foo(aa1);
    int[int] aa2;
    foo(aa2);
}


DMD 2.058beta2 gives:

...\dmd2\src\phobos\std\typecons.d(379): Error: cannot implicitly convert expression (_param_0) of type int to char
test.d(3): Error: template instance std.typecons.Tuple!(char).Tuple.__ctor!(int) error instantiating
...\dmd2\src\phobos\std\algorithm.d(382):        instantiated from here: __lambda2!(int)
test.d(3):        instantiated from here: map!(Result)
test.d(9):        instantiated from here: foo!(int,int)
...\dmd2\src\phobos\std\algorithm.d(382): Error: template instance test.foo!(int,char).foo.__lambda2!(int) error instantiating
test.d(3):        instantiated from here: map!(Result)
test.d(9):        instantiated from here: foo!(int,int)