[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
Sat Feb 4 10:05:11 PST 2012


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



--- Comment #20 from timon.gehr at gmx.ch 2012-02-04 10:05:05 PST ---
(In reply to comment #19)
> (In reply to comment #18)
> > (In reply to comment #17)
> > > try at a minimum immutable, mutable, and inout.  If more than one of these
> > > typechecks, the call is ambiguous.
> > 
> > What if one is a better match than the other? If it should fail I think we
> > should use the repaired overload resolution. It has exactly the required
> > semantics.
> 
> Example?  How can immutable match "better" than mutable?  I guess it would
> depend on the definition of "better".

class A{
    A x()const{return new A;}
    alias x this;
}

int foo(immutable(A) x){return 1;}
int foo(A x){return 2;}

static assert(foo(new immutable(A)) == 1);

The overload is resolved to the first function because it is an exact match
whereas the second overload is a match with implicit conversions. Your proposed
rules would always use the alias this when matching an inout(A) parameter, and
that is probably not what is wanted. Interestingly, the compiler currently
seems to explore the alias this of the alias this of the alias this... and
never terminates. (Also see issue 7437).

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