D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6313 - Type deduction with const/in
Summary: Type deduction with const/in
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-14 04:50 UTC by bearophile_hugs
Modified: 2014-03-19 19: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 2011-07-14 04:50:53 UTC
A D2 program:


T[] foo(T)(const T[] x) {
    //static assert(is(U == int)); // false
    static assert(is(T == const(int)));
    return new T[1];
}
U[] bar(U)(const U[] y) {
    static assert(is(U == int));
    return foo(y);
}
void main() {
    bar([1]);
}


DMD 2.054 gives:
test.d(8): Error: cannot implicitly convert expression (foo(y)) of type const(int)[] to int[]
test.d(11): Error: template instance test.bar!(int) error instantiating


This causes me problems because many of my functions have "in" arguments. When they call each other they don't compile, as in this example (here I have used "const" arguments just for clarity).


To solve the problem I have had to use code like this, that I don't like a lot:

Unqual![] foo(T)(const T[] x) {
    return new Unqual!T[1];
}
U[] bar(U)(const U[] y) {
    return foo(y);
}
void main() {
    bar([1]);
}


So, is it possible (and good) to change DMD so the type T of foo is "int" instead of "const(int)"?


See also comments by Daniel Murphy:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=28147
Comment 1 Infiltrator 2014-03-19 19:02:14 UTC
The provided code (minus the static assert in foo()) compiles and runs as of v2.065.