www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4968] New: inout is sticky to function return type

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4968

           Summary: inout is sticky to function return type
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: tomash.brechko gmail.com


--- Comment #0 from Tomash Brechko <tomash.brechko gmail.com> 2010-10-01
14:57:27 PDT ---
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 :(.
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 01 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4968


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy yahoo.com


--- Comment #1 from Steven Schveighoffer <schveiguy yahoo.com> 2010-10-04
06:06:46 PDT ---
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)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 04 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4968



--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2011-05-06 09:21:13 PDT ---
Created an attachment (id=964)
test patch

This patch only fix comment#1 case, but not support more cases (array,
function, delegate, etc.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 06 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4968


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 Attachment #964 is|0                           |1
           obsolete|                            |


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2011-05-06 22:14:25 PDT ---
Created an attachment (id=965)
Improvement

Posted pull request:
https://github.com/D-Programming-Language/dmd/pull/58

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 06 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4968


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2011-08-31 08:07:52 PDT ---
*** This issue has been marked as a duplicate of issue 3748 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 31 2011