[Issue 7543] inout opApply should work properly

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 9 12:30:36 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7543


timon.gehr at gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr at gmx.ch


--- Comment #5 from timon.gehr at gmx.ch 2012-03-09 12:30:41 PST ---
(In reply to comment #4)
> (In reply to comment #3)
> > We'll need a clear spec of what it means to have inout at two nesting levels of
> > a function signature.
> 
> This follows naturally from variance rules:
> [snip.]

I think you may misunderstand this issue.

> Also the following subtyping rules for inout apply (R2 <: R1):
> R2 delegate(inout(T)) <: R1 delegate(immutable(T))
> R2 delegate(inout(T)) <: R1 delegate(const(T))
> R2 delegate(inout(T)) <: R1 delegate(T)
> And of course:
> R2 delegate(inout(T)) <: R1 delegate(inout(T))
> 
> From that follows (given two types A,B and B <: A):
> B delegate(immutable(A)) <: A delegate(inout(A))
> 

No, it does not. This is not sound.

class A{immutable(A) get(){return null;}}
class B:A{
    immutable(A) other;
    this(immutable(A) other){this.other = other;}
    override immutable(A) get(){return other;}
}

A delegate(inout(A)) dg = (immutable(A) a) => new B(a);
A a = new A;
A x=dg(a);
immutable(A) b = x.get();

// now a is mutable, b is immutable and (a is b).

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


More information about the Digitalmars-d-bugs mailing list