--- Comment #7 from Steven Schveighoffer <> 2012-01-26 
10:21:28 PST ---
(In reply to comment #6)
> (In reply to comment #5)
> > Let's assume inout
> > did resolve to const for foo, and the function could be called:
> > 
> > immutable int x = 5;
> > immutable(int)* xp = &x;
> > immutable(int)** xpp = &xp;
> > 
> > const(int *)* y = foo(xpp);
> > 
> > int z = 2;
> > 
> > *y = &z; // this should pass, since I can assign int* to const(int*).
> You cannot assign anything to const(int*), that is the point of const.

Oh yeah :)  Stupid me, for some reason in my head this made sense because there
was a mutable part.

> > 
> > immutable(int *)* foo(immutable(int *)* x) // inout == immutable
> >     const(int *)* foo(    const(int *)* x) // inout == const
> >           int **  foo(          int **  x) // inout == mutable
> > 
> > none of these can be called with immutable(int)** because there is no 
> > implicit
> > cast to the parameter.  I don't think const(immutable(int)*)* reduces to
> > const(int *)*.
> It does. The second version is callable with immutable(int)**. Not fixing this
> would mean there are cases where code duplication is more expressive than
> inout.

You are right.  So we need to come up with some rules for inout as to how it

What about this idea?

for each inout parameter, we try as a substitute in order: mutable, immutable,
inout, const.  See if the argument can be implicitly converted to the
substituted parameter.

If none of the possible substitutes can be implicitly converted to for a single
parameter, the function fails to be called, and an error is generated "inout
cannot be resolved [for parameter x]"

If substitutes can be found for all of the inout parameters, and they all match
(i.e. all mutable, all immutable, all inout or all const), then that is used as
the substitute and the function is called.

If substitutes are different (e.g. one is mutable, but another is immutable),
then const is used as the substitute.  The parameters are then re-checked to
see that they all implicitly convert to the substituted const type.  If this is
not possible, an error is generated "common inout substitute cannot be found".

I think this should be as capable as duplicate functions.

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

Reply via email to