[Issue 7355] inout incorrectly resolved if the same type has both mutable and immutable parts
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 26 09:55:38 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7355
--- Comment #6 from timon.gehr at gmx.ch 2012-01-26 09:55:37 PST ---
(In reply to comment #5)
> (In reply to comment #3)
>
> > The typeof resolves to error because inout resolves to immutable.
>
> As I said, it should fail to match or match mutable and fail to call. I'm not
> sure which is correct, but I feel either way that the assert should fail. If
> it's resolving to immutable, I think it's a bug, not because it's not passing,
> but because it's failing for the wrong reason.
>
> I think your expectations would be a violation of const.
No.
> 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.
>
> assert(*xp == 2);
> z = 3;
> assert(*xp == 3); // oops! changed data perceived as immutable!
>
> Is there an error in my example? I think it comes down to this:
>
> 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.
>
> This does take some mental effort, so I may have made a mistake :) I hate
> double pointers...
We have:
immutable(T) is a subtype of const(T).
=> immutable(int) :< const(int)
const(T*) :< const(S*) iff const(T) :< const(S)
=> const(immutable(int)*) :< const(int*)
const(T)* :< const(S)* iff const(T) :< const(S)
=> const(immutable(int)*)* : const(int*)*
qed
--
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