Bug 6313 – Type deduction with const/in

Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-07-14T04:50:00Z
Last change time
2014-03-19T19:02:14Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-07-14T04:50:53Z
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 by lt.infiltrator — 2014-03-19T19:02:14Z
The provided code (minus the static assert in foo()) compiles and runs as of v2.065.