On Tue, 20 Jul 2010 16:19:50 +0000, dsimcha wrote:

> Bug 2594 (http://d.puremagic.com/issues/show_bug.cgi?id=2594) has
> languished in Bugzilla for about 1.5 years and really irks me. 
> Furthermore, std.math.pow(), for example, doesn't work when passed
> immutable values.  In other words, right now you can't do:
> 
> immutable uint foo = 5;
> immutable uint bar = 2;
> uint baz = foo ^^ bar;
> 
> Lots of functions in Phobos, as well as libs I've written, have
> basically this bug, and fixing/preventing all instances of it is a
> monumental and tedious task.
> 
> Therefore, I propose that implicit function template instantiation
> automatically runs the equivalent of a shallow Unqual on its non-ref
> arguments before determining the types.  In other words, if a
> const/immutable object could be implicitly cast to shallow mutable, it
> is.  For example:
> 
> void fun(T, U)(T arg1, U arg2) {
>     // Do stuff that assumes arg1, arg2 are shallowly mutable.
> }
> 
> void main() {
>     immutable uint foo = 3;
>     immutable char[] bar = "bar";
> 
>     // This instantiates fun with T = uint and U = // immutable(char)[],
>     NOT T = immutable uint and // U = immutable char[].
>     fun(foo, bar);
> }
> 
> This would prevent a lot of nasty bugs but would be safe because
> arguments passed by value are shallowly copied and therefore can safely
> be made shallowly mutable, which is why implicitly casting between fully
> const/immutable and shallowly mutable is allowed already by the spec.

++vote

-Lars

Reply via email to