Boscop <> changed:

           What    |Removed                     |Added
                 CC|                            |

--- Comment #4 from Boscop <> 2012-03-09 10:24:53 PST ---
(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:
In-arguments are contravariant, so you can pass anything whose type is a
subtype of the argument type. Then the usual rules of function subtyping apply
(e.g. see bug 7676)
So, if you have a function of type "R1 function(R2 delegate(inout(T1)) f)" you
can pass anything for f that is a subtype of "R2 delegate(inout(T1))". For
argument types to the delegate, the subtyping rules apply again.
Since in-arguments are contravariant (and return types (and types of out-args)
are covariant), any value of type "R delegate(T)" where (R <: R2 and inout(T1)
<: T) is a subtype of "R2 delegate(inout(T1))" (<: is the subtype relation).

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))

Which is exactly what we want. (Analogous for functions. Btw, functions should
be a subtype of delegates).

class A {}
class B : A {}
void foo(A function(A function(inout(A))) dg);
B bar(A function(inout(A)) f);
B baz(inout(A) a);
foo(bar(baz(new immutable(A))));
foo(bar(baz(new const(A))));
foo(bar(baz(new A)));

so it all works out nicely...

To make this work in DMD, it has to support function subtyping according to
variance rules. It's important that functions with an inout arg are subtypes of
functions with an immutable/const/mutable arg (all other arg types / return
type being equal) because the former can be substituted for one of the latter.

(This issue is related to bug 7542.)

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to