www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6912] New: non-transitivity of inout breaks const system

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

           Summary: non-transitivity of inout breaks const system
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timon.gehr gmx.ch


--- Comment #0 from timon.gehr gmx.ch 2011-11-08 16:03:34 PST ---
Consider:

int[] y;

inout(const(int)[]) foo(inout(int) x){
    y=new int[10];
    const(int)[] q = y;
    inout a = q;
    return a;
}

void main(){
    immutable int x;
    immutable int[] oops = foo(x);
    assert(is(typeof(oops[0]) == immutable));
    auto oldoops_0 = oops[0];
    y[0]++;
    assert(oops[0] != oldoops_0);
}


This is caused by the fact that !is(inout(const(int)[])==inout(int[])), i.e.
inout is currently non-transitive in certain cases and making it 'override'
const transitively will fix the issue.

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


Steven Schveighoffer <schveiguy yahoo.com> changed:

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


--- Comment #1 from Steven Schveighoffer <schveiguy yahoo.com> 2011-11-09
06:35:05 PST ---
inout a = q;

This line should fail to compile.  const does not implicitly cast to inout.

Note that:

immutable a = q;

doesn't work.  inout should follow the same restrictions.

I don't think this has to do with transitivity (and indeed, inout cannot
override const or immutable).  It's just a simple case of inout cannot be
implicitly cast from something else.

Remember, inout can get implicitly cast back to immutable or mutable upon
function return.  I don't think inout should override *any* qualifiers without
casts.

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


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|non-transitivity of inout   |const(T[])/immutable(T[])
                   |breaks const system         |can be implicitly cast to
                   |                            |inout(const(T)[])/inout(imm
                   |                            |utable(T)[])


--- Comment #2 from timon.gehr gmx.ch 2011-11-09 08:58:10 PST ---
(In reply to comment #1)
 inout a = q;
 
 This line should fail to compile.  const does not implicitly cast to inout.
 
Yes, but the issue here is that it casts to inout(const(int)[]). (dmd rejects casting const(int[]) to inout(int[]) for exampe)
 Note that:
 
 immutable a = q;
 
 doesn't work.  inout should follow the same restrictions.
 
 I don't think this has to do with transitivity (and indeed, inout cannot
 override const or immutable).  It's just a simple case of inout cannot be
 implicitly cast from something else.
 
 Remember, inout can get implicitly cast back to immutable or mutable upon
 function return.  I don't think inout should override *any* qualifiers without
 casts.
You are right, it is not a transitivity/overriding issue. Currently inout(const(T)) == inout(immutable(T)) == inout(T). That is bad, for example, how to represent the element type of inout(const(char)[]) ? (DMD treats it as const(char), which is obviously wrong, it should be inout(const(char)).) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6912


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, rejects-valid
           Platform|Other                       |All


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2011-11-09 21:38:49 PST ---
https://github.com/D-Programming-Language/dmd/pull/504

This patch will forbid some conversions like follows.
e.g. const(int)[]    to inout(const(int)[])
     const(int)[int] to inout(const(int)[int]).

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


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid               |accepts-invalid


--- Comment #4 from Steven Schveighoffer <schveiguy yahoo.com> 2011-11-10
05:36:46 PST ---
I think this should be accepts-invalid, since the given example code should not
compile.

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



--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2011-11-10 06:07:48 PST ---
(In reply to comment #4)
 I think this should be accepts-invalid, since the given example code should not
 compile.
Wow, I'm sorry, and thank you for your fix. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 10 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6912



--- Comment #6 from Steven Schveighoffer <schveiguy yahoo.com> 2011-11-10
06:49:38 PST ---
(In reply to comment #5)
 (In reply to comment #4)
 I think this should be accepts-invalid, since the given example code should not
 compile.
Wow, I'm sorry, and thank you for your fix.
Don't worry about it! The main fix is the patch, my change was a nitpick :) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 10 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6912


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


--- Comment #7 from Walter Bright <bugzilla digitalmars.com> 2011-11-14
21:11:55 PST ---
https://github.com/D-Programming-Language/dmd/commit/9583a773f8c748ac22872b2fcb5acd3de9bc0186

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