[Issue 7542] inout parameter contravariant should be allowed
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Mar 9 10:46:37 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7542
Boscop <kingboscop at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kingboscop at gmail.com
--- Comment #4 from Boscop <kingboscop at gmail.com> 2012-03-09 10:46:41 PST ---
(In reply to comment #2)
> This pull breaks the type system:
>
> void main(){
> // conversion from void function(int*) to void function(inout(int)*):
> void function(inout(int)*) wfp = function(int*)(*p = 1;}
You can't do that because void function(int*) is a supertype of void
function(inout(int)*).
(as I described in comment 4 of bug 7543).
One wants to be able to do:
void fooM(int*);
void fooC(const(int)*);
void fooI(immutable(int)*);
void function(const(int)*) wfp;
wfp = &fooM;
wfp = &fooC;
wfp = &fooI;
This is only possible when the following subtyping rules are obeyed:
T <: const(T)
immutable(T) <: const(T)
And we also have:
T* <: const(T)*
immutable(T)* <: const(T)*
(
And btw:
T* <: const(T)* <: const(T*)
immutable(T)* <: immutable(T*) <: const(T*)
)
And of course the usual function subtyping rules (types of in-arguments are
contravariant and types of out-arguments and return types are covariant).
--
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