Comment #0 by tomash.brechko — 2010-10-01T14:57:27Z
Call to writeln(f(i)) below won't compile because dmd 2.049 thinks f() returns "inout(int)", so "void writeln(T...)(T args)" expands to "void writeln(inout(int)...(inout(int) args)", and inout parameter requires inout return type. Rewriting "void" as "inout(void)" helps, but obviously is wrong.
import std.stdio;
inout(int)
f(inout int i)
{
return i;
}
void
main()
{
int i;
writeln(typeof(f(i)).stringof); // Outputs "inout(int)", not "int".
int j = f(i);
writeln(i); // Works OK :).
writeln(f(i)); // Won't compile :(.
}
Comment #1 by schveiguy — 2010-10-04T06:06:46Z
This is a good catch. Although inout doesn't work currently, so don't expect much yet.
IMO, this is how the compiler should behave:
void foo(T)(T t)
{
writeln(typeof(t).stringof);
}
inout(int)
f(inout(int) i)
{
return i;
}
void main()
{
int i;
const int j;
immutable int k;
foo(f(i));
foo(f(j));
foo(f(k));
}
should print:
int
const(int)
immutable(int)
Comment #2 by k.hara.pg — 2011-05-06T09:21:13Z
Created attachment 964
test patch
This patch only fix comment#1 case, but not support more cases (array, function, delegate, etc.)