Bug 4968 – inout is sticky to function return type

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-10-01T14:57:00Z
Last change time
2011-08-31T08:07:52Z
Keywords
patch
Assigned to
nobody
Creator
tomash.brechko

Attachments

IDFilenameSummaryContent-TypeSize
964test.patchtest patchtext/plain1900
965patch4968.patchImprovementtext/plain2382

Comments

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.)
Comment #3 by k.hara.pg — 2011-05-06T22:14:25Z
Created attachment 965 Improvement Posted pull request: https://github.com/D-Programming-Language/dmd/pull/58
Comment #4 by k.hara.pg — 2011-08-31T08:07:52Z
*** This issue has been marked as a duplicate of issue 3748 ***